X
xwm21cn
Unregistered / Unconfirmed
GUEST, unregistred user!
在DELPHI的INTRAWEB程序中,建立一个子线程,但子线程需要访问主线程的东西,比如需要做“FormMain.IWTimer1.Enabled := false;”,我用Synchronize方法,但FormMain = nil,请大侠支招!十分感谢!!
下面是程序片断:
TClientThread = class(TThread)
private
sBuffer: BufferType;
// Private declarations
protected
procedure GiveAnswer;
public
procedure Execute;
override;
end;
procedure TClientThread.GiveAnswer;
begin
FormMain.IWTimerSubmit.Enabled := false;
// FormMain 为nil,故会报错
FormMain.IWLabel1.Caption := 'test';
end;
Procedure TClientThread.Execute;
begin
FreeOnTerminate := True;
Priority := tpNormal;
While (not Terminated)do
begin
Synchronize(GiveAnswer);
end;
end;
下面是程序片断:
TClientThread = class(TThread)
private
sBuffer: BufferType;
// Private declarations
protected
procedure GiveAnswer;
public
procedure Execute;
override;
end;
procedure TClientThread.GiveAnswer;
begin
FormMain.IWTimerSubmit.Enabled := false;
// FormMain 为nil,故会报错
FormMain.IWLabel1.Caption := 'test';
end;
Procedure TClientThread.Execute;
begin
FreeOnTerminate := True;
Priority := tpNormal;
While (not Terminated)do
begin
Synchronize(GiveAnswer);
end;
end;