word文件*.doc如何保存到数据库里面去?又如何从数据库里面读出来?为什么下面编译通不过~!(100分)

  • 主题发起人 主题发起人 ccad
  • 开始时间 开始时间
C

ccad

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button1Click(Sender: TObject);
var
Stream1:TBlobStream;
begin
olecontainer1.CreateObjectFromFile('C:/qqq.doc',false);
Stream1:= TBlobStream.Create(Table1.fieldbyname('aaa') , bmwrite);
//编译出错(access ole字段)<---Incompatible type:'TBlobField'and'Tfield'
OleContainer1.SavetoStream(Stream1);
Table1.post;
end;
 
下面的程序对你或许有帮助
procedure TsampleForm.OpenDOCClick(Sender: TObject);
var
MemSize: Integer;
Buffer: PChar;
fStream: TFileStream;
bStream: TBlobStream;
begin

OpenDialog1.Filter:='WORD文档(*.DOC)|*.DOC';{从对话窗选择文件}
if OpenDialog1.Execute then

begin

fStream:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
with table1 do
{'table1'为含BLOB字段的表名}
begin
Open;
Edit;
bStream := TBlobStream.Create(FieldByName('Doc') as TBlobField, bmWrite);
{'Doc'为BLOB字段名}
MemSize := fStream.Size;
Inc(MemSize);
{Make room for the buffer's null terminator.}
Buffer := AllocMem(MemSize);
{Allocate the memory.}
try
bStream.Seek(0, soFrombegin
ning);
{Seek 0 bytes from the stream's end point}
fStream.Read(Buffer^,MemSize);
bStream.Write(Buffer^,MemSize);
finally
fStream.Free;
bStream.Free;
end;
try
Post;
except
on E: EDatabaseError do
if HandelException(E)< >0 then
exit
else
raise;
end;
end;
do
c_ole.CreateObjectFromFile(OpenDialog1.FileName,False);
do
c_ole.Run;{Doc_ole为ToleContainer构件名}
end;

end;

---- 以上为向数据库中写入的程序,应用中从对话窗取出文件在ToleContainer
构件中显示的同时存入数据库。
procedure TsampleForm.GetDocClick(Sender: TObject);
var
MemSize: Integer;
Buffer: PChar;
fStream: TFileStream;
bStream: TBlobStream;
begin

MyFile:=TFileStream.Create('c:/temp.tmp',fmCreate);
with Query1 do

begin

Stream := TBlobStream.Create(FieldByName('Doc') as TBlobField, bmRead);
MemSize := Stream.Size;
Inc(MemSize);
{Make room for the buffer's null terminator.}
Buffer := AllocMem(MemSize);
{Allocate the memory.}
try
Stream.Read(Buffer^,MemSize);
MyFile.Write(Buffer^,MemSize);
finally
MyFile.Free;
Stream.Free;
end;

end;

if FileExists('c:/temp.DOC') then

DeleteFile('c:/temp.DOC');
if FileExists('c:/temp.tmp') then

begin

RenameFile('c:/temp.tmp', 'c:/temp.DOC');
do
c_ole.CreateObjectFromFile('c:/temp.DOC',False);
do
c_ole.Run;
end;

end;

---- 以上程序为从数据库从将WORD文档取出,并放在temp.doc的临时文件上并在
ToleContainer构件中显示。
 
if HandelException(E)< >0 then
exit //编译出错undeclared identifier:'HandelException'
 
为什么会编译出错?
fStream:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
 
后退
顶部