关于Delphi4在线程中调用OLE的问题!

kola 2000-01-11 09:49:00
我用Delphi4在线程中调用CreateOleObject('Word.Application').不知为何总出现
"尚未调用CoInitialize"的错误.据我所知Delphi4在Uses中加入Comobj就已经始化Ole
对象了,不知却为何出现这个情况?另外如果不使用线程就不会出错!可是速度奇慢,而且在
一段时间内无法做其它事,不知哪位大侠可以解决在线程中调用CreateOleObject出错的
问题,并恳请赐教如何在程序中加快Ole的调用速度问题.
...全文
174 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
tiger 2000-01-11
  • 打赏
  • 举报
回复
请在Application.Initialize前赋值, 第二个问题我的机器启动很快, 只能说声爱莫能助了. 你可以看一看comobj的源码

program Project1;

uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas',
comobj;

{$R *.RES}

begin
CoInitFlags := 0;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
kola 2000-01-11
  • 打赏
  • 举报
回复
Tiger!谢谢!可是加入CoInitFlags: Integer = -1;后还是出现一样的错!另外我的机子
启动Word没有那么慢!我的问题涉及到了Com组件的问题!与机子性能无关!只是说能否从编
程技巧上来提高其执行速度!
tiger 2000-01-11
  • 打赏
  • 举报
回复
comobj.pas
{ CoInitFlags determines the COM threading model of the application or current
thread. This bitflag value is passed to CoInitializeEx in ComServ initialization.
Assign COINIT_APARTMENTTHREADED or COINIT_MULTITHREADED to this variable before
Application.Initialize is called by the project source file to select a
threading model. Other CoInitializeEx flags (such as COINIT_SPEED_OVER_MEMORY)
can be OR'd in also. }
var
CoInitFlags: Integer = -1; // defaults to no threading model, call CoInitialize()

另外, 你起word慢不慢? 慢的话, 检查你的机器吧.
kola 2000-01-11
  • 打赏
  • 举报
回复
谢谢Tiger!

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧