动态创建的Button的事件代码怎么写?(50分)

  • 主题发起人 SevenOrient
  • 开始时间
S

SevenOrient

Unregistered / Unconfirmed
GUEST, unregistred user!
比如,我动态创建了一Buttonx数组
buttonx的Click事件怎么触发?里面代码怎么写?
比如我想buttonx的onclick事件里:ShowMessage(intTOstr(i)).
怎么写?
 
单独写一个buttononclick过程,在动态创建时用button.onclick:=buttononclick
就可以了,i就用button的taborder,注意taborder在创建时也要赋值
 
procedure buttononclick(sender : TObject);
begin
showmessage(inttostr(sender as tbutton).tag));
end;

procedure tform1.createbuttoon;
begin
with tbutton.create(self) do
begin
parent:= self;
visible:= true;
tag:= 1;
onclick=buttonclick;
end;
end;
 
多人接受答案了。
 
顶部