鸿 网 互 联 www.68idc.cn

当前位置 : 服务器租用 > 编程语言开发 > delphi > >

封装了三个对TMemoryStream操作的函数,大牛莫笑

来源:互联网 作者:佚名 时间:2017-09-20 09:56
// TMemoryStream 转化为string字符串 function MemoryStreamToString(M: TMemoryStream): AnsiString; begin SetString(Result, PChar(M.Memory), M.Size div SizeOf(Char)); end ; // TMemoryStream 写入string字符串 procedure MemoryAddStr(M:TMemoryStr
//  TMemoryStream 转化为string字符串
function MemoryStreamToString(M: TMemoryStream): AnsiString;
begin
 SetString(Result, PChar(M.Memory), M.Size div SizeOf(Char));
end;
//  TMemoryStream 写入string字符串
procedure MemoryAddStr(M:TMemoryStream;cStr:String);
begin
  if M=nil then
    M:=TMemoryStream.Create;
   M.Write(cStr[1],Length(cStr)*Sizeof(char));
end;
//  TMemoryStream 保存到文件
procedure MemoryStreamSaveToFile(M:TMemoryStream;cFileName:String);
 Var
   FStream:TFileStream;
 begin
   if FileExists(cFileName) then
     begin
       FStream:=TFileStream.Create(cFileName,fmOpenWrite or fmShareDenyWrite);
       FStream.Position:=FStream.Size;
     end else
       FStream:=TFileStream.Create(cFileName,fmCreate or fmShareDenyWrite);
   FStream.Write(M.Memory^,M.Position);
   FStream.Free;
 end;

 

网友评论
<