WORD do cument, OleContainer,BlobStream and BlobField(100分)

  • 主题发起人 主题发起人 river
  • 开始时间 开始时间
R

river

Unregistered / Unconfirmed
GUEST, unregistred user!
i am using a OleContainer to load and modify MS WORD document,
and using OleContainer.SaveToStream to save data to TBlobStream which
is using to write to a TBlobField.

Problem:the first click in NewBlobButton is ok,but the second click is wrong,the wrong line is " OleContainer1.SaveToStream(obBlobStream);" with the message: "BLOB not opened"

program as follow:

procedure TForm1.FormCreate(Sender: TObject);
begin
Table1.Open;
Table1.First;
if Table1.Bof then
Table1.Append;
OleContainer1.CreateObjectFromFile('new.doc',False);
end;

procedure TForm1.NewBlobButtonClick(Sender: TObject);
var
obBlobStream:TBlobStream;
begin
Table1.Edit;
obBlobStream:=TBlobStream.Create(Table1ob,bmReadWrite); { Table1ob is BlobField }
OleContainer1.SaveToStream(obBlobStream); {***wrong in the cliking in second time with message: "blob not open"***}
Table1.Post;
obBlobStream.Free;
table1.Append;
OleContainer1.CreateObjectFromFile('new.doc',False);
end;

请问错在那里?
 
table1ob怎么(哪里)定义的? 也许问题出在那里
 

Table1.Edit; //第二次click时, Table 处于Append状态, 执行Edit 命令自然会出错. 删除这句或加个table的状态判断.
obBlobStream:=TBlobStream.Create(Table1ob,bmReadWrite); { Table1ob is BlobField }
OleContainer1.SaveToStream(obBlobStream); {***wrong in the cliking in second time with message: "blob not open"***}
Table1.Post;
obBlobStream.Free;
table1.Append; //这句执行后, table处于Append的状态.
OleContainer1.CreateObjectFromFile('new.doc',False);
end;
 
Tabl1ob:TBlobField;

Table1.Edit; 未出错.
是 OleContainer1.SaveToStream(obBlobStream); 在第二次点击时错:
错误信息: "blob not open"
 
讨论几次没什么结果,总的来说是连续两次存储一条blob时会出此错误。但你的问题
是已经增加了一条记录,按理说不会出错的。
 
改为如下写法:
if table1.state = dsBrowse then //判断是否为正常状态
table1.Append; //这句执行后, table处于Append的状态.
obBlobStream:=TBlobStream.Create(Table1ob,bmReadWrite);
OleContainer1.SaveToStream(obBlobStream);
Table1.Post;
obBlobStream.Free;
OleContainer1.CreateObjectFromFile('new.doc',False);


 
这样改一下:

procedure TForm1.FormCreate(Sender: TObject);
begin
Table1.Open;
Table1.First;
//if Table1.Bof then
// Table1.Append;
OleContainer1.CreateObjectFromFile('new.doc',False);
end;

procedure TForm1.NewBlobButtonClick(Sender: TObject);
var
obBlobStream:TmemoryStream;
begin
Table1.append;
obBlobStream:=TmemoryStream.Create;
OleContainer1.SaveToStream(obBlobStream);
tblobfield(table1.fieldbyname('table1ob')).loadfromsteam(olecontainer1);
Table1.Post;
obBlobStream.Free;
//table1.Append;
OleContainer1.CreateObjectFromFile('new.doc',False);
end;

 
我找到错误了, Table1.Post;
obBlobStream.Free;

应该是: obBlobStream.Free;
Table1.Post;
 
恭喜eYes专家分超过10000!!!!


向你学习。 t_t
 
多人接受答案了。
 

Similar threads

I
回复
0
查看
1K
import
I
I
回复
0
查看
3K
import
I
I
回复
0
查看
3K
import
I
I
回复
0
查看
2K
import
I
I
回复
0
查看
3K
import
I
后退
顶部