这是我的一段代码,看看对你有用否
type
TStreamHead = record
Signature: Integer; //$434F4442
DrawAspect: Integer; //1
DataSize: Integer; //stream.size;
end;
Ttree=record
id:string;
wjlx:string;
mc:string;
end;
........
取出
procedure Tfrmword.tv1Change(Sender: TObject; Node: TTreeNode);
var
rtree
tree;
word_id:string;
mem :Tmemorystream;
Stream1:Tstream;
st:TStringStream;
blobstream:Tblobstream;
head: TStreamHead;
ms ,stream: Tmemorystream;
begin
if node.Level=0 then
begin
self.pm1.Items[0].Visible :=true; //添加子项
self.pm1.Items[1].Visible :=true; //添加子项
exit
end
else
begin
self.pm1.Items[0].Visible :=false; //添加子项
self.pm1.Items[1].Visible :=false; //添加子项
end;
OleContainer1.Visible :=false;
rtree:=node.Data;
word_id:=rtree.id;
with qry1 do
begin
close;
sql.Clear;
sql.Add('select * from word where id='''+word_id+'''');
open;
end;
stream:=TMemoryStream.Create;
ms := TMemoryStream.Create;
TBlobfield(qry1.FieldByName('内容')).SaveToStream(stream); //"内容"字段为Image类型
if stream.Size = 0 then
begin
stream.Free;
exit;
end;
frmWait :=TfrmWait.Create(self);
frmWait.Show;
frmWait.Update;
with head do
begin
Signature := $434F4442;
DrawAspect := 1;
DataSize := stream.size;
end;
ms.WriteBuffer(head,sizeof(head));
ms.CopyFrom(stream,0) ;
ms.Position := 0;
olecontainer1.LoadFromStream(ms);
self.OleContainer1.Visible :=true;
OleContainer1.DoVerb (1);
self.OleContainer1.Align :=AlClient;
// olecontainer1.OleObject.application.CommandBars['Standard'].Visible:=false;
//// olecontainer1.OleObject.application.CommandBars['Formatting'].Visible:=false;
// olecontainer1.OleObject.application.CommandBars['Tables and Borders'].Visible:=false;
tv1.SetFocus; //为了去除菜单
frmWait.Free;
frmWait :=nil;
{tblobfield(qry1.FieldByName('内容')).SaveToFile('d:/test.doc');
self.OleContainer1.CreateObjectFromFile(tmppath,false);
self.OleContainer1.DoVerb(1) ;
tv1.SetFocus;
这段语句也没有问题,只不过通过外部文件过渡,时间效率都很慢 }
end;
--------
以下为保存
procedure Tfrmword.btn1Click(Sender: TObject);
var
rptree
tree;
begin
if tv1.Selected.Level=0 then
begin
getmsg('information','请选择子节点');
exit;
end
else
begin
rptree:=tv1.Selected.Data;
if dlgopen1.Execute then
begin
qry1.Close;
qry1.SQL.Clear;
qry1.SQL.Add('select * from word where id='''+rptree.id+'''');
qry1.open;
qry1.edit;
TBlobField(qry1.FieldByName('内容')).LoadFromFile(dlgopen1.FileName);
qry1.Post;
self.OleContainer1.CreateObjectFromFile(dlgopen1.FileName,false);
self.OleContainer1.Visible :=true;
self.OleContainer1.DoVerb(1);
tv1.SetFocus;
end;
end;
end;