I’m dynamically creating command buttons on the form like this:
procedure TForm1.cmdAddClick(Sender: TObject);
var MenuButton : TButton;
begin MenuButton := TButton.Create(self);
ButtonCount:=ButtonCount + 1;
With MenuButton do
begin
Top:= 10 + Height * ButtonCount;
Left := 10;
Parent := Panel1; //Parent container for the buttons.
OnClick := @YouClicked;
Caption := 'Menu item ' + IntToStr(ButtonCount);
end;
end;
After a few times of running the above lines, I have a number of buttons.
But How do I REMOVE a specific button?
I’ve tried
FreeAndNil (TButton(Sender));
But it doesn’t seem to work…
1 Answer