运行时生成的组件怎么调用
运行时生成的组件如何调用?
比如,用下面的过程可以生成一个按钮bt,bt在public已预先声明:
Procedure TForm1.Button1Click(Sender: TObject);
Begin
bt:=tbutton.create(self);
bt.parent:=self;
bt.Name:='btnm';
bt.left:=20;
bt.top:=20;
bt.width:=40;
bt.height:=25;
bt.caption:='exit';
bt.visible:=true;
bt.visible:=true;
End;
我怎样为按钮bt的onclick事件编程?
------解决方案--------------------
------解决方案--------------------
procedure tform1.btonclick(sender:integer);
begin
showmessage('bt clicked!' );
close;
end;
要改成
procedure tform1.btonclick(Sender:TObject);
begin
showmessage('bt clicked!' );
close;
end;
比如,用下面的过程可以生成一个按钮bt,bt在public已预先声明:
Procedure TForm1.Button1Click(Sender: TObject);
Begin
bt:=tbutton.create(self);
bt.parent:=self;
bt.Name:='btnm';
bt.left:=20;
bt.top:=20;
bt.width:=40;
bt.height:=25;
bt.caption:='exit';
bt.visible:=true;
bt.visible:=true;
End;
我怎样为按钮bt的onclick事件编程?
------解决方案--------------------
Procedure TForm1.Button1Click(Sender: TObject);
Begin
bt:=tbutton.create(self);
bt.parent:=self;
bt.Name:='btnm';
bt.left:=20;
bt.top:=20;
bt.width:=40;
bt.height:=25;
bt.caption:='exit';
bt.visible:=true;
bt.visible:=true;
bt.OnClick :=btonclick; // OnClick事件
End;
------解决方案--------------------
procedure tform1.btonclick(sender:integer);
begin
showmessage('bt clicked!' );
close;
end;
要改成
procedure tform1.btonclick(Sender:TObject);
begin
showmessage('bt clicked!' );
close;
end;