读书人

运行时生成的组件怎么调用

发布时间: 2013-12-15 22:17:19 作者: rapoo

运行时生成的组件如何调用?
比如,用下面的过程可以生成一个按钮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;

读书人网 >.NET

热点推荐