首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

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

2013-12-15 
运行时生成的组件如何调用?比如,用下面的过程可以生成一个按钮bt,bt在public已预先声明:Procedure TForm1.

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

热点排行