N
niaoqiu
Unregistered / Unconfirmed
GUEST, unregistred user!
OLE打开word文档时常常会导致系统没响应,或者常常出现“服务器关闭”等提示,不知道是什么原因?
具体的源代码如下:
//删除现存文件
DeleteFile('c:/temp.doc');
DeleteFile('c:/temp.tmp');
MyFile:=TFileStream.Create('c:/temp.tmp',fmCreate);
with query do
begin
Stream:= TBlobStream.Create(FieldByName(fieldName) 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.tmp') then
begin
if not RenameFile('c:/temp.tmp', 'c:/temp.doc') then
begin
userError('发生错误,无法打开文件!');
exit;
end;
ole.CreateObjectFromFile('c:/temp.doc',False);
ole.Run;
ole.DoVerb(1);
end;
具体的源代码如下:
//删除现存文件
DeleteFile('c:/temp.doc');
DeleteFile('c:/temp.tmp');
MyFile:=TFileStream.Create('c:/temp.tmp',fmCreate);
with query do
begin
Stream:= TBlobStream.Create(FieldByName(fieldName) 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.tmp') then
begin
if not RenameFile('c:/temp.tmp', 'c:/temp.doc') then
begin
userError('发生错误,无法打开文件!');
exit;
end;
ole.CreateObjectFromFile('c:/temp.doc',False);
ole.Run;
ole.DoVerb(1);
end;