程序运行时提示内存出错!!! ( 积分: 0 )

  • 主题发起人 主题发起人 lijun175165721
  • 开始时间 开始时间
L

lijun175165721

Unregistered / Unconfirmed
GUEST, unregistred user!
//****************************************************************************//
//把word文档以ole数据形式存入数据库,再用OleCOntainer控件把它从数据库中显示出来
//****************************************************************************//
procedure TForm1.Button2Click(Sender: TObject);
var
FileName:String;
FileStream:TFileStream;
BlobStream:TBlobStream;
Buffer:PChar;
MemSize:Integer;
begin
if OpenDialog1.Execute then
begin
FileName:=OpenDialog1.FileName;
end;
try
FileStream:=TFileStream.Create(FileName,fmOpenRead);
MemSize:=FileStream.Size;
inc(MemSize);
Buffer:=AllocMem(MemSize);
FileStream.Seek(0,SoFromBeginning);
FileStream.Read(Buffer^,MemSize);
ADOTable1.Append;
BlobStream:=TBlobStream.Create(ADOTable2.FieldByName('Doc') as TBlobField,bmWrite);
BlobStream.Write(Buffer^,MemSize);
ADOTable1.Post;
finally
BlobStream.Free;
FileStream.Free;
ADOTable2.Close;
end;

end;
上面的程序运行时老是提示内存出错!!!,请各位大虾指点!!!
 
//****************************************************************************//
//把word文档以ole数据形式存入数据库,再用OleCOntainer控件把它从数据库中显示出来
//****************************************************************************//
procedure TForm1.Button2Click(Sender: TObject);
var
FileName:String;
FileStream:TFileStream;
BlobStream:TBlobStream;
Buffer:PChar;
MemSize:Integer;
begin
if OpenDialog1.Execute then
begin
FileName:=OpenDialog1.FileName;
end;
try
FileStream:=TFileStream.Create(FileName,fmOpenRead);
MemSize:=FileStream.Size;
inc(MemSize);
Buffer:=AllocMem(MemSize);
FileStream.Seek(0,SoFromBeginning);
FileStream.Read(Buffer^,MemSize);
ADOTable1.Append;
BlobStream:=TBlobStream.Create(ADOTable2.FieldByName('Doc') as TBlobField,bmWrite);
BlobStream.Write(Buffer^,MemSize);
ADOTable1.Post;
finally
BlobStream.Free;
FileStream.Free;
ADOTable2.Close;
end;

end;
上面的程序运行时老是提示内存出错!!!,请各位大虾指点!!!
 
设断点跟踪,看是在哪行报的错?
 
是不是 OpenDialog1.Execute 这句提示出错?
 
可以不用BlobStream吗, 我一直是按以下的方式操作的:
FileStream.position:=0;
TBlobField(ADOTable2.FieldByName('Doc')).LoadFromStream(FileStream);
ADOTable.post;
 
这种情况多数都是创建的对象没释放或试图访问释放了的对象。查对象吧。
 
BlobStream:=TBlobStream.Create(ADOTable2.FieldByName('Doc') as TBlobField,bmWrite);
是这一行报错的!
谢谢大家对我的帮助.
 
后退
顶部