G
guoxp
Unregistered / Unconfirmed
GUEST, unregistred user!
在下在做delphi数据库的时候遇到如下一个 olecontainer的问题,代码如下:
这段代码中有条语句creatobjectfromfile()那里老出错,而且与数据库的sql语句相关联
{即,我在query组件中用语句
DataModule_bszz.Q_BSDA_CONT.close;
DataModule_bszz.Q_BSDA_CONT.sql.clear;
DataModule_bszz.Q_BSDA_CONT.sql.add('SELECT * FROM BS_BSDA_CONT WHERE 标书编码=:标书编码');//用
这条语句的话,有时候控件出现word 文件与纯文本文件转换等小窗口,或者,如果我数据库里的索引S_vaule长度有时候
是3有时是1,那么它将来在ole控件里只能读出长度为3的,而长度为1的则不行了,报ole错误。
如果我把过滤语句写成where 标书索引='+''''+s_value+'''';则长度为三的索引中有一条可以读出,而另外两条读不出
,我感觉这是好奇怪的问题,就来问问大家,putfile过程是olecontainer显示word文档的语句。
DataModule_bszz.Q_BSDA_CONT.Open;
except
DataModule_bszz.Q_BSDA_CONT.execsql;
end;
DataModule_bszz.Q_BSDA_CONT.locate('标书索引',s_value,[]);
PutFile;
}
procedure Tform8.PutFile;
var
MemSize: Integer;
Buffer: PChar;
MyFile: TFileStream;
Stream: TBlobStream;
begin
statusbar1.Panels[0].text := '正在处理,请稍侯...';
statusbar1.refresh;
screen.Cursor := CrHourGlass;
if FileExists('c:/temp.tmp')
then DeleteFile('c:/temp.tmp');
MyFile := TFileStream.Create('c:/temp.tmp', fmCreate);
with DataModule_bszz.Q_BSDA_CONT do
begin
Stream := TBlobStream.Create(FieldByName('标书文本') 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');
OleContainer1.CreateObjectFromFile
('c:/temp.doc', False);
OleContainer1.Run;
end;
statusbar1.Panels[0].text := '';
statusbar1.refresh;
screen.Cursor := Crdefault;
end;
这段代码中有条语句creatobjectfromfile()那里老出错,而且与数据库的sql语句相关联
{即,我在query组件中用语句
DataModule_bszz.Q_BSDA_CONT.close;
DataModule_bszz.Q_BSDA_CONT.sql.clear;
DataModule_bszz.Q_BSDA_CONT.sql.add('SELECT * FROM BS_BSDA_CONT WHERE 标书编码=:标书编码');//用
这条语句的话,有时候控件出现word 文件与纯文本文件转换等小窗口,或者,如果我数据库里的索引S_vaule长度有时候
是3有时是1,那么它将来在ole控件里只能读出长度为3的,而长度为1的则不行了,报ole错误。
如果我把过滤语句写成where 标书索引='+''''+s_value+'''';则长度为三的索引中有一条可以读出,而另外两条读不出
,我感觉这是好奇怪的问题,就来问问大家,putfile过程是olecontainer显示word文档的语句。
DataModule_bszz.Q_BSDA_CONT.Open;
except
DataModule_bszz.Q_BSDA_CONT.execsql;
end;
DataModule_bszz.Q_BSDA_CONT.locate('标书索引',s_value,[]);
PutFile;
}
procedure Tform8.PutFile;
var
MemSize: Integer;
Buffer: PChar;
MyFile: TFileStream;
Stream: TBlobStream;
begin
statusbar1.Panels[0].text := '正在处理,请稍侯...';
statusbar1.refresh;
screen.Cursor := CrHourGlass;
if FileExists('c:/temp.tmp')
then DeleteFile('c:/temp.tmp');
MyFile := TFileStream.Create('c:/temp.tmp', fmCreate);
with DataModule_bszz.Q_BSDA_CONT do
begin
Stream := TBlobStream.Create(FieldByName('标书文本') 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');
OleContainer1.CreateObjectFromFile
('c:/temp.doc', False);
OleContainer1.Run;
end;
statusbar1.Panels[0].text := '';
statusbar1.refresh;
screen.Cursor := Crdefault;
end;