阿
阿当
Unregistered / Unconfirmed
GUEST, unregistred user!
我在线程中执行如下代码: 请各位看看,救救我。
//执行后出错,提示“由于应用程序发出与输入同步的调用,因此无法进行外部调用”
//我已经用Synchronize同步了,如果不用Sychronize同步更不行
//我应该怎么做?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ComObj,
StdCtrls;
type
TTestThread = class(TThread)
private
procedure OpenWord;
public
procedure Execute; override;
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
TestThread: TTestThread;
public
{ Public declarations }
end;
var
Form1: TForm1;
WordApp: OLEVariant;
implementation
{$R *.DFM}
{ TestThread }
procedure TTestThread.Execute;
begin
//Synchronize(OpenWord);
OpenWord;
//还有其它代码
end;
procedure TTestThread.OpenWord;
begin
Screen.Cursor := crHourGlass;
try
wordApp := GetActiveOleObject('Word.Application');
except
try
wordApp := CreateOleObject('Word.Application');
except
ShowMessage('无法打开Word!');
Exit;
end;
end;
Screen.Cursor := crDefault;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
TestThread := TTestThread.Create(False);
end;
end.
//执行后出错,提示“由于应用程序发出与输入同步的调用,因此无法进行外部调用”
//我已经用Synchronize同步了,如果不用Sychronize同步更不行
//我应该怎么做?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ComObj,
StdCtrls;
type
TTestThread = class(TThread)
private
procedure OpenWord;
public
procedure Execute; override;
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
TestThread: TTestThread;
public
{ Public declarations }
end;
var
Form1: TForm1;
WordApp: OLEVariant;
implementation
{$R *.DFM}
{ TestThread }
procedure TTestThread.Execute;
begin
//Synchronize(OpenWord);
OpenWord;
//还有其它代码
end;
procedure TTestThread.OpenWord;
begin
Screen.Cursor := crHourGlass;
try
wordApp := GetActiveOleObject('Word.Application');
except
try
wordApp := CreateOleObject('Word.Application');
except
ShowMessage('无法打开Word!');
Exit;
end;
end;
Screen.Cursor := crDefault;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
TestThread := TTestThread.Create(False);
end;
end.