码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-01-16 07:34:12      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

//  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;

 

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

标签:

原文地址:http://www.cnblogs.com/wuxi15/p/5134863.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!