Converting TMemoryStream to 'String' in Delphi 2009

后端 未结 7 970
南方客
南方客 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:29

    You can cast it into the right sized character pointer and just simple assign it:

    procedure getMemoryStreamAsString( aMS_ : TMemoryStream );
    var
      ws : widestring; // in newer Delphi it can be string
      ans : ansistring;
    begin
      ws := pwidechar( aMS_.memory );
      // OR
      ans := pansichar( aMS_.memory );
    end;
    

提交回复
热议问题