Board index » delphi » Events of controls created at run time.

Events of controls created at run time.

Hi,

How can I tell Delphi what to do when the user clicks one button if this
button was created at run time ?

In other words... where and how do I have to put the ..OnClick method ?

Thank you.

 

Re:Events of controls created at run time.


<<Santi Serrano:
How can I tell Delphi what to do when the user clicks one button if this
button was created at run time ?

In other words... where and how do I have to put the ..OnClick method ?

Quote

Hi !

You have to write the OnClick handler, similar to the one created designtime when doubleclicking the
button:

TForm1.ClikcRuntimeCreatedBtn(Sender: TObject);
begin
  With Sender as TButton do begin
      // do whatever you vant it to do...
  end;
end;

procedure TForm1.CreateButton;
var
 Btn: TButton;
begin
  Btn:=TButton.Create(Self);
  Btn.Parent:=Self;
  Btn.Top:=100;
  Btn.Left:=100;
  Btn.OnClick:=ClickRuntimeCreatedBtn;
  Btn.Visible:=true;
end;

Good luck !

--

Bjoerge

Other Threads