I have a button on a form.
The button name is bmod2, while the form name is fLayOut1
When a user clicks the button I would like to save the name of the current form and button name
procedure TFLayout1.bMod2Click(Sender: TObject);
var
azone : string;
adept : string;
begin
azone := //forum name here
adept := //button name here
end;
To get name of the current form that the event method belongs to, you can access the
Nameproperty directly or through the hiddenSelfobject as it’s shown in the commented line of code below.To get name of the component that has fired a certain event, in this case the
OnClickevent, you can use commonly usedSenderparameter, which is (usually) the reference to the object, that caused the event to fire. Since the passedSenderparameter is of baseTObjectclass type, which doesn’t have theNameproperty yet, you need to typecast this object to a type, that theNameproperty has. It might be directly a type of the object having the event binded or, if you are not sure with it, or if there might be more component types binded to an event, you can use e.g. the commonTComponentancestor class, which theNameproperty defines (as it’s shown in the commented line in the following code):