title: Delphi ReadStreamStr, WriteStreamStr implementation check
body: <p>I'm using these implementations that I found on another post on SO. But when reading a string in sometimes, ReadStreamStr puts in extra characters into the string. So I'm posting my implementation here to have it checked and approved, and if there is a fault, corrected. </p>
  
  <pre><code>function ReadStreamStr(Stream: TStream): string;
  { returns a string from the stream }
  var
    LenStr: Integer;
  begin
    Result := '';
    { get length of string }
    LenStr := ReadStreamInt(Stream);
    { set string to get memory }
    SetLength(Result, LenStr);
    { read characters }
    Stream.Read(Result[1], LenStr);
  end;
  
  procedure WriteStreamStr(Stream: TStream; Str: string);
  { writes a string to the stream }
  var
    StrLen: Integer;
  begin
    { get length of string }
    StrLen := ByteLength(Str);
    { write length of string }
    WriteStreamInt(Stream, StrLen);
    if StrLen &gt; 0 then
      { write characters }
      Stream.Write(Str[1], StrLen);
  end;
  </code></pre>
  
  <p>Thank you.</p>