L
lanse_fengye
Unregistered / Unconfirmed
GUEST, unregistred user!
以下的代码是一个多线程的类。
其它的执行都正常,但当执行到objWordApp:= CreateOleObject('Word.Application');这一句就报错,
错误信息如下:
“raised exception calss EOleSysError with message '尚未调用CoInitialize.'”
如果哪位大侠知道原因的话,烦请告知。小弟不胜感激!!!小弟谢先了! :)
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, StdCtrls,ComObj;
type
TMyThread=class(TThread)
private
Fedt: TEdit;
FobjWordApp: variant;
protected
procedure Execute();override;
public
constructor Create(edt: TEdit;objWordApp: variant);
end;
implementation
constructor TMyThread.Create(edt: TEdit;objWordApp: variant);
begin
Fedt:= edt;
FobjWordApp:= objWordApp;
FreeOnTerminate:= True;
inherited Create(false);
end;
procedure TMyThread.Execute;
var
intIndex: integer;
objWordApp: variant;
begin
while Truedo
begin
intIndex:= strtointdef(trim(Fedt.Text),0);
intIndex:= intIndex + 1;
Fedt.Text:= inttostr(intIndex);
if intIndex >= 100000 then
break;
end;
[red]objWordApp:= CreateOleObject('Word.Application');[/red]
end;
end.
其它的执行都正常,但当执行到objWordApp:= CreateOleObject('Word.Application');这一句就报错,
错误信息如下:
“raised exception calss EOleSysError with message '尚未调用CoInitialize.'”
如果哪位大侠知道原因的话,烦请告知。小弟不胜感激!!!小弟谢先了! :)
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, StdCtrls,ComObj;
type
TMyThread=class(TThread)
private
Fedt: TEdit;
FobjWordApp: variant;
protected
procedure Execute();override;
public
constructor Create(edt: TEdit;objWordApp: variant);
end;
implementation
constructor TMyThread.Create(edt: TEdit;objWordApp: variant);
begin
Fedt:= edt;
FobjWordApp:= objWordApp;
FreeOnTerminate:= True;
inherited Create(false);
end;
procedure TMyThread.Execute;
var
intIndex: integer;
objWordApp: variant;
begin
while Truedo
begin
intIndex:= strtointdef(trim(Fedt.Text),0);
intIndex:= intIndex + 1;
Fedt.Text:= inttostr(intIndex);
if intIndex >= 100000 then
break;
end;
[red]objWordApp:= CreateOleObject('Word.Application');[/red]
end;
end.