unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Label1: TLabel; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; count:integer;implementation uses unit2; {$R *.DFM}procedure Tform1.creat(sender:tobject); begin count:=1; end;procedure TForm1.Button1Click(Sender: TObject); var thread1:mythread; begin thread1.CreateIt(label1); inc(COUNT); 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 //count:=1; Label1:=l1; inherited create(false);end; procedure mythread.show; begin form1.Label1.Caption:=inttostr(count); freeOnterminate:=true; // inherited create(true); end; procedure mythread.Execute; begin repeat synchronize(show); until Terminated; { Place thread code here } end;end.
unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Label1: TLabel; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; count:integer;implementation uses unit2; {$R *.DFM}procedure Tform1.creat(sender:tobject); begin count:=1; end;procedure TForm1.Button1Click(Sender: TObject); var thread1:mythread; begin thread1.CreateIt(label1); inc(COUNT); 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 //count:=1; Label1:=l1; inherited create(false);end; procedure mythread.show; begin form1.Label1.Caption:=inttostr(count); freeOnterminate:=true; // inherited create(true); end; procedure mythread.Execute; begin repeat synchronize(show); until Terminated; { Place thread code here } end;end.我运行了,没有报错!
constructor mythread.CreateIt(var l1:TLabel);
begin
count:=1;
Label1:=l1;
inherited create(false);
end;
procedure mythread.show;
begin
form1.Label1.Caption:=inttostr(count);
freeOnterminate:=true;
end;
我原来想显示该线程所占用的内存数,现在线程都运行不了了,只好改了
我的mail:[email protected]
3:原来我想动态生成一个标签,然后传给线程显示,现在没有使用
4:那怎么做呢
我想得到结果
5:给个qq咱们快点聊
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
count:integer;implementation
uses unit2;
{$R *.DFM}procedure Tform1.creat(sender:tobject);
begin
count:=1;
end;procedure TForm1.Button1Click(Sender: TObject);
var
thread1:mythread;
begin
thread1.CreateIt(label1);
inc(COUNT);
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
//count:=1;
Label1:=l1;
inherited create(false);end;
procedure mythread.show;
begin
form1.Label1.Caption:=inttostr(count);
freeOnterminate:=true;
// inherited create(true);
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);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
count:integer;implementation
uses unit2;
{$R *.DFM}procedure Tform1.creat(sender:tobject);
begin
count:=1;
end;procedure TForm1.Button1Click(Sender: TObject);
var
thread1:mythread;
begin
thread1.CreateIt(label1);
inc(COUNT);
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
//count:=1;
Label1:=l1;
inherited create(false);end;
procedure mythread.show;
begin
form1.Label1.Caption:=inttostr(count);
freeOnterminate:=true;
// inherited create(true);
end;
procedure mythread.Execute;
begin
repeat
synchronize(show);
until Terminated;
{ Place thread code here }
end;end.我运行了,没有报错!