Converting TMemoryStream to 'String' in Delphi 2009

后端 未结 7 905
南方客
南方客 2020-11-28 05:52

We had the following code prior to Delphi 2009:

function MemoryStreamToString(M : TMemoryStream): String;
var
    NewCapacity: Longint;
begin
    if (M.Size          


        
相关标签:
7条回答
  • 2020-11-28 06:38

    I use:

    function StreamToString(const Stream: TStream; const Encoding: TEncoding): string;
    var
      StringBytes: TBytes;
    begin
      Stream.Position := 0;
      SetLength(StringBytes, Stream.Size);
      Stream.ReadBuffer(StringBytes, Stream.Size);
      Result := Encoding.GetString(StringBytes);
    end;
    

    It has been tested with Delphi XE7 only.

    0 讨论(0)
提交回复
热议问题