用delphi2005
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
Unit2;type
TForm1 = class(TForm)
Memo1: TMemo;
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
thread:GGProgress;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
thread:=GGProgress.Create(true);//挂起
thread.Resume;
end;end.unit Unit2;interfaceuses
Classes;type
GGProgress = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
procedure ShowMsg;
public
{ Public declarations }
end;implementation
uses Unit1;procedure GGProgress.Execute;
begin
synchronize(ShowMsg);
end;procedure GGProgress.ShowMsg;
begin
Form1.Caption := 'Updated in a thread';
end;
end.
不知道这样有什么问题,就是打不到预期目的
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
Unit2;type
TForm1 = class(TForm)
Memo1: TMemo;
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
thread:GGProgress;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
thread:=GGProgress.Create(true);//挂起
thread.Resume;
end;end.unit Unit2;interfaceuses
Classes;type
GGProgress = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
procedure ShowMsg;
public
{ Public declarations }
end;implementation
uses Unit1;procedure GGProgress.Execute;
begin
synchronize(ShowMsg);
end;procedure GGProgress.ShowMsg;
begin
Form1.Caption := 'Updated in a thread';
end;
end.
不知道这样有什么问题,就是打不到预期目的
你可以用另一种方法,向Form1发送自定义消息,
定义一个自定义消息,然后SendMessage给Form1
在Form1中处理这个消息,
建议该成:thread:=GGProgress.Create(false);不要挂起,试试
不行就用另外一种方法,给主窗口发送消息 sendmessage(form1.handle,WM_settext,0,integer(pchar('update in..')));
我用DELPHI 7,没出现什么问题呀,Form1.Caption := 'Updated in a thread';有作用啊