我从我运行的网站上尝试了一个脚本
http://www.delphi-central.com/runtime.aspx并取得成功.
http://www.delphi-central.com/runtime.aspx并取得成功.
private { Private declarations } procedure CustomButtonClick(Sender: TObject);
procedure TForm1.AddNewButtonClick(Sender: TObject); var NewButton : TButton; begin NewButton := TButton.create(self); with NewButton do begin Top := 30; Width := 60; Left := Width * (self.ControlCount-2); Parent := self; OnClick := CustomButtonClick; Caption := 'Button '+ inttostr (self.ControlCount-2); end; //With end; procedure TForm1.DeleteLastButtonClick(Sender: TObject); begin if Self.ControlCount>2 then TButton (Controls[ControlCount-1]).destroy; end; procedure TForm1.CustomButtonClick(Sender: TObject); begin ShowMessage(TButton(Sender).caption + ' Pressed'); end;
但如果我更改OnClick,
OnClick := CustomButtonClick; ==> OnClick := DeleteLastButtonClick;