Arsip: Konversi Stream


by agusmade in Articles more 13 years ago 5377
jika anda sering bermasalah dalam menggunakan stream, berikut ada beberapa rutin yang biasa saya gunakan untuk mengkonversikan stream.
//Stream Convertion
//agus made k (agusmade@yaoo.com)
{ File to String  }
function filetostring(afilename:string):string;
var fl:TFileStream;
begin
fl:=TFileStream.Create(afilename,fmOpenRead or fmShareCompat);
SetLength(result,fl.Size);
fl.Read(result[1],fl.Size);
fl.Free;
end;
{ String to File  }
procedure stringtofile(acontent,afilename:string);
var fl:TFileStream;
begin
fl:=TFileStream.Create(afilename,fmOpenWrite or fmCreate);
fl.Write(acontent[1],length(acontent));
fl.Free;
end;
{ Stream to String  }
function stringtofile(adata:TStream):string;
var str:TStringStream;
s:string;
begin
str:=TStringStream.Create(s);
str.CopyFrom(adata,adata.size);
result:=str.datastring;
str.free;
end;
{ String to Stream  }
procedure stringtofile(s:String;adata:TStream);
var str:TStringStream;
begin
str:=TStringStream.Create(s);
adata.CopyFrom(str,str.size);
str.free;
result:=str.datastring;
str.free;
end;
Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com