unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
count:integer;
implementation
uses unit2;
{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var
thread1:mythread;
begin
thread1.CreateIt(label1);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
count:=1;
end;end.
...............................
unit Unit2;interfaceuses
Classes,StdCtrls,SysUtils;type
mythread = class(TThread)
private
// count:integer;
Label1:TLabel;
{ Private declarations }
protected
procedure Execute; override;
public
constructor CreateIt(var l1:TLabel);
procedure show;
end;implementation
uses unit1;
{ Important: Methods and properties of objects in VCL can only be used in a
method called using Synchronize, for example, Synchronize(UpdateCaption); and UpdateCaption could look like, procedure mythread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }{ mythread }
constructor mythread.CreateIt(var l1:TLabel);
begin
Label1:=l1;
freeOnterminate:=true;
inherited create(true);
end;
procedure mythread.show;
begin
form1.Label1.Caption:=inttostr(count);end;
procedure mythread.Execute;
begin
repeat
synchronize(show);
until Terminated;
{ Place thread code here }
end;end.
.
同志们谁帮我看看,怎么编译没有问题,运行有错呢,我想在动态创建的标签上显示当前线程的运行,而且每开一个就要显示一个,怎么作呢,最好给我一段代码
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
count:integer;
implementation
uses unit2;
{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var
thread1:mythread;
begin
thread1.CreateIt(label1);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
count:=1;
end;end.
...............................
unit Unit2;interfaceuses
Classes,StdCtrls,SysUtils;type
mythread = class(TThread)
private
// count:integer;
Label1:TLabel;
{ Private declarations }
protected
procedure Execute; override;
public
constructor CreateIt(var l1:TLabel);
procedure show;
end;implementation
uses unit1;
{ Important: Methods and properties of objects in VCL can only be used in a
method called using Synchronize, for example, Synchronize(UpdateCaption); and UpdateCaption could look like, procedure mythread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }{ mythread }
constructor mythread.CreateIt(var l1:TLabel);
begin
Label1:=l1;
freeOnterminate:=true;
inherited create(true);
end;
procedure mythread.show;
begin
form1.Label1.Caption:=inttostr(count);end;
procedure mythread.Execute;
begin
repeat
synchronize(show);
until Terminated;
{ Place thread code here }
end;end.
.
同志们谁帮我看看,怎么编译没有问题,运行有错呢,我想在动态创建的标签上显示当前线程的运行,而且每开一个就要显示一个,怎么作呢,最好给我一段代码
begin
Label1:=l1;
freeOnterminate:=true;
inherited create(false);
end;