你需要一个OLEContainer来显示Doc文件。
下面给你一段例子:
写入数据库:
procedure TForm1.Button6Click(Sender: TObject);
var
st:TStringStream;
begin
with OpenDialog1 do
begin
Filter:='WORD文檔(*.doc)|*.doc';
if Execute then
begin
st := tstringstream.create('');
olecontainer1.CreateObjectFromFile(FileName,true);
olecontainer1.SaveToStream(st);
with Table1 do
begin
Open;
Edit;
TBlobField(FieldByName('简介')).LoadFromStream(st);
try
Table1.Post;
finally
st.Free;
end;
end;
end;
end;
end;
从数据库读出:
procedure TForm1.Button8Click(Sender: TObject); //使用blobstream读取BLOB字段。
var
blobstream:Tblobstream;
begin
blobStream := TBlobStream.Create(Tblobfield(Table1.FieldByName('简介')), bmRead);
showmessage(INTTOSTR(BlobStream.Size));
if BlobStream.Size = 0 then begin
BlobStream.Free;
Exit;
end;
BLOBstream.position:=0;
olecontainer1.LoadFromStream(BLOBstream);
BLOBstream.Free;
end;