楼主的逆操作是指用word读数据么?那得宏实现吧。和程序没什么关系。
procedure TsampleForm.OpenDOCClick(Sender: TObject);
var
MemSize: Integer;
Buffer: PChar;
MyFile: TFileStream;
Stream: TBlobStream;
begin
OpenDialog1.Filter:='WORD文档(*.DOC)|*.DOC'
;{从对话窗选择文件}
if OpenDialog1.Execute then begin
MyFile:=TFileStream.Create
(OpenDialog1.FileName,fmOpenRead);
with table1 do {‘table1’为含BLOB字段的表名}
begin
Open;
Edit;
Stream := TBlobStream.Create(FieldByName('Doc')
as TBlobField, bmWrite);
{‘Doc’为BLOB字段名}
MemSize := MyFile.Size;
Inc(MemSize); {Make room for the
buffer's null terminator.}
Buffer := AllocMem(MemSize);
{Allocate the memory.}
try
Stream.Seek(0, soFromBeginning);
{Seek 0 bytes from the stream's end point}
MyFile.Read(Buffer^,MemSize);
Stream.Write(Buffer^,MemSize);
finally
MyFile.Free;
Stream.Free;
end;
try
Post;
except
on E: EDatabaseError do
if HandelException(E)< >0 then exit
else
raise;
end;
end;
Doc_ole.CreateObjectFromFile
(OpenDialog1.FileName,False);
Doc_ole.Run;{Doc_ole为ToleContainer构件名}
end;
end;
---- 以上为向数据库中写入的程序,应用中从对话窗取出文件在ToleContainer构件中显示的同时存入数据库。
procedure TsampleForm.GetDocClick
(Sender: TObject);
var
MemSize: Integer;
Buffer: PChar;
MyFile: TFileStream;
Stream: 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');
Doc_ole.CreateObjectFromFile('c:/temp.DOC',False);
Doc_ole.Run;
end;
end;
---- 以上程序为从数据库从将WORD文档取出,并放在temp.doc的临时文件上并在ToleContainer构件中显示。
算是用流实现的例子吧。我以前贴过的。看有没有帮助