频道分类

delphi 将MemoryStream保存到字符串

作者:admin 来源: 日期:2020/6/1 21:24:01 人气: 标签:

 
var
  mStream:    TMemoryStream;
  thisString: string;
begin
  mStream := TMemoryStream.Create;
  try
    mStream.LoadFromFile('Unit1.Pas');
    if mStream.Size > 0 then begin
      SetLength(thisString, mStream.Size);
      Move(mStream.Memory^, thisString[1], mStream.Size);
    end;
  finally
    mStream.Free;
  end;
  if Length(thisString) > 0 then
    RichEdit1.Text := thisString;
end;


//仅供参考


TheString: string;
TheStream: TmemoryStream;
..
TheStream := TMemoryStream.Create;
< your code >
SetLength( TheString, TheStream.Size);
TheStream.Position := 0;
TheStream.Write( TheString[1], Length(TheString));
TheStream.Free;

上一篇:Delphi 中将TMemoryStream转换为'String'下一篇:没有资料