Writing a string to a stream in Delphi

There are two tricks to this. Most of this comes from what Embarcadero suggests on how to write a string to a stream. Another website suggested multiplying the length times the number of bytes to make sure the code works on both unicode and non-unicode builds, something one would be wise to consider when developing legacy code on Delphi 7, that may someday get ported to a newer version. One less thing to worry about later.

procedure WriteStringToStream(stream: TStream; const appendText: string);
begin
  stream.WriteBuffer(Pointer(appendText)^, Length(appendText)*SizeOf(Char));
end;