Y
Yohoho999
Unregistered / Unconfirmed
GUEST, unregistred user!
我在D6+Winxp SP2下编写了以下程序,请问两个Edit的内容怎么不同步更新呢?
unit test1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
TrackBar1: TTrackBar;
TrackBar2: TTrackBar;
Label3: TLabel;
Label4: TLabel;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TMyThread=class(tthread)
Fm,Fn:integer;
FEdit:TEdit;
procedure Show;
constructor create(m,n:Integer;myEdit:TEdit);
procedure execute;override;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TMyThread }
constructor TMyThread.create(m, n: Integer; myEdit: TEdit);
begin
inherited create(false);
Fm:=m;
Fn:=n;
FEdit:=myEdit;
freeonterminate:=true; // 线程终止时自动删除对象,
end;
procedure TMyThread.execute;
begin
synchronize(show); // 线程调用同步
end;
procedure TMyThread.Show;
var
i:Integer;
begin
for i:=Fm to Fn do
begin
FEdit.Text:='循环到:'+IntToStr(i);
FEdit.Update;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
T1,T2:TmyThread;
begin
Edit1.Text:='';
Edit2.Text:='';
T1:=TMyThread.create(1,20000,Edit1);
T2:=TMyThread.create(20001,50000,Edit2);
end;
end.
unit test1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
TrackBar1: TTrackBar;
TrackBar2: TTrackBar;
Label3: TLabel;
Label4: TLabel;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TMyThread=class(tthread)
Fm,Fn:integer;
FEdit:TEdit;
procedure Show;
constructor create(m,n:Integer;myEdit:TEdit);
procedure execute;override;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TMyThread }
constructor TMyThread.create(m, n: Integer; myEdit: TEdit);
begin
inherited create(false);
Fm:=m;
Fn:=n;
FEdit:=myEdit;
freeonterminate:=true; // 线程终止时自动删除对象,
end;
procedure TMyThread.execute;
begin
synchronize(show); // 线程调用同步
end;
procedure TMyThread.Show;
var
i:Integer;
begin
for i:=Fm to Fn do
begin
FEdit.Text:='循环到:'+IntToStr(i);
FEdit.Update;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
T1,T2:TmyThread;
begin
Edit1.Text:='';
Edit2.Text:='';
T1:=TMyThread.create(1,20000,Edit1);
T2:=TMyThread.create(20001,50000,Edit2);
end;
end.