L
lb3141
Unregistered / Unconfirmed
GUEST, unregistred user!
我想把一个图片存入文件中,当然,文件中存的还有其它数据。但不知为什么总报地址错误,请哪位大虾帮忙以下,感激不禁!
procedure TForm1.Button1Click(Sender: TObject);
var
FileHandle : Integer;
S: TMemoryStream;
ASize: Integer;
P: PChar;
begin
//测试文件
FileHandle := FileOpen('b.txt', fmOpenWrite);
if not FileHandle > 0 then
Exit;
//这里是测试,所以只存了图片
S :=TMemoryStream.Create;
Image1.Picture.Graphic.SaveToStream(S);
S.Position :=0;
ASize :=S.Size;
P :=PChar(AllocMem(ASize+1));
S.ReadBuffer(p,ASize);
FileWrite(FileHandle,p,ASize);
FileClose(FileHandle);
FreeMem(P);
S.Clear;
S.Free;
end;
//过程运行没错,但不知什么地方报地址错!
procedure TForm1.Button1Click(Sender: TObject);
var
FileHandle : Integer;
S: TMemoryStream;
ASize: Integer;
P: PChar;
begin
//测试文件
FileHandle := FileOpen('b.txt', fmOpenWrite);
if not FileHandle > 0 then
Exit;
//这里是测试,所以只存了图片
S :=TMemoryStream.Create;
Image1.Picture.Graphic.SaveToStream(S);
S.Position :=0;
ASize :=S.Size;
P :=PChar(AllocMem(ASize+1));
S.ReadBuffer(p,ASize);
FileWrite(FileHandle,p,ASize);
FileClose(FileHandle);
FreeMem(P);
S.Clear;
S.Free;
end;
//过程运行没错,但不知什么地方报地址错!