You can assign the same handler to all four button OnClick
events. The event's Sender
parameter will tell you which button is triggering the event each time. For example:
void __fastcall TMyForm::ButtonClick(TObject *Sender)
{
TButton *btn = static_cast<TButton*>(Sender);
ShowMessage("You clicked on " + btn->Name);
}
If your code needs to behave depending on which button is clicked, you can use the Tag
property to differentiate, for example:
void __fastcall TMyForm::ButtonClick(TObject *Sender)
{
TButton *btn = static_cast<TButton*>(Sender);
switch (btn->Tag)
{
...
}
}