title: Convert TMemoryStream to WideString in Delphi 7
body: <p>When I use this code and function in <strong>Delphi 7</strong> an error message will be displayed :</p>
  
  <p><strong>This code convert MemoryStream content to WideString</strong></p>
  
  <pre><code>function ReadWideString(stream: TStream): WideString;
  var
    nChars: LongInt;
  begin
    stream.Position := 0;
    stream.ReadBuffer(nChars, SizeOf(nChars));
    SetLength(Result, nChars);
    if nChars &gt; 0 then
      stream.ReadBuffer(Result[1], nChars * SizeOf(Result[1]));
  end;
  
  
  procedure TForm1.Button2Click(Sender: TObject);
  var
    mem: TMemoryStream;
  begin
    mem := TMemoryStream.Create;
    mem.LoadFromFile('C:\Users\User1\Desktop\wide.txt');
    Memo1.Lines.Add(ReadWideString(mem));
  end;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/ZrIYv.png" alt="enter image description here"></p>
  
  <p>Any help would be greatly appreciated.</p>