自己写的一个类 直接用 内存流 也可以的
TMemoryData=Class(TStream)
private
Fdata
ointer;
FdataSize:integer;
public
destructor Destroy;override;
function Empty:Boolean;
procedure Load_From_file(const FileName:string);
procedure Load_From_Stream(S:TStream);
procedure Save_to_Stream(S:TStream);
procedure Save_to_file(const fileName:string);
procedure SetData(data
ointer;size:integer);
property DataSize:integer read FdataSize write FDataSize;
end;
implementation
destructor TMemoryData.Destroy;
begin
if Not Empty then
freemem(Fdata,FdataSize);
inherited Destroy;
end;
function TMemoryData.Empty:Boolean;
begin
Result:=FDatasize=0;
end;
procedure TMemoryData.Load_From_file(const FileName:string);
var
F:TFileStream;
begin
try
F:=TFileStream.create(FileName,fmOpenRead);
Load_From_Stream(F);
finally
F.free;
end;
end;
procedure TMemoryData.Load_From_Stream(S:TStream);
begin
if Not Empty then
freeMem(Fdata,FdataSize);
FdataSize:=S.size;
Fdata:=AllocMem(FdataSize);
s.read(Fdata^,fdatasize);
// showmessage(string(fdata^));
end;
procedure TMemoryData.Save_to_Stream(S:TStream);
begin
if NOt Empty then
S.Write(FData^,Fdatasize);
end;
procedure TMemoryData.Save_to_file(const fileName:string);
var
F:TFileStream;
begin
F:=TFileStream.Create(fileName,fmCreate);
try
Save_to_Stream(F);
finally
F.Free;
end;
end;
procedure TMemoryData.SetData(data
ointer;size:integer);
begin
if NOt Empty then
freeMem(fdata,Fdatasize);
FdataSize:=size;
// FData:=AllocMem(fdatasize);
Fdata:=data;
end;