稻
稻草
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure myclick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
var
lab:Tlabel;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer ;
begin
for i:=1 to 5 do
begin
lab:=Tlabel.Create(self);
lab.Parent:=form1;
lab.Name:='A'+inttostr(i);
lab.Caption:='abcd'+inttostr(i);
lab.Top:=60;
lab.Left:=i*90;
lab.OnClick:=myclick;
lab.Show;
end;
end;
procedure Tform1.myclick(Sender: TObject);
begin
showmessage(lab.Caption);
end;
end.
单击其中的一个label想显示它的caption,可是结果是最后的一个控件的caption
请问有什么办法???
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure myclick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
var
lab:Tlabel;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer ;
begin
for i:=1 to 5 do
begin
lab:=Tlabel.Create(self);
lab.Parent:=form1;
lab.Name:='A'+inttostr(i);
lab.Caption:='abcd'+inttostr(i);
lab.Top:=60;
lab.Left:=i*90;
lab.OnClick:=myclick;
lab.Show;
end;
end;
procedure Tform1.myclick(Sender: TObject);
begin
showmessage(lab.Caption);
end;
end.
单击其中的一个label想显示它的caption,可是结果是最后的一个控件的caption
请问有什么办法???