Reputation: 21
I need assistance for trying to get the name of a dynamically created button using and OnClick event in Delphi.
I am then want to use the name of that button and store it in a global variable.
This is where I am currently:
procedure TMap.FormShow(Sender: TObject);
var
btnCache : TButton;
begin
btnCache := TButton.Create(imgAerial);
with btnCache do
begin
onclick := ClickButton;
end;
procedure TMap.ClickButton(Sender: TObject);
begin
//Code for getting the name of the button
end;
Upvotes: 0
Views: 2015
Reputation: 613531
The button's name can be retrieved by casting Sender
to the type that introduces Name
. That is TComponent
.
(Sender as TComponent).Name
Don't expect this name to be very informative since your code does not assign a name to the button. As the code is written in the question, the dynamically created button has no name.
Upvotes: 4