Default
Google

How can I use the same event for multiple Buttons?

Applies To: C++Builder 1 or higher
Category: Knowledge Base

 
I have 3 Buttons on my form and I want to use the same OnClick event for all of them. How can this be done?
 
 1.
  Start a new application.
 
 2.
  Add three (3) Buttons.
 
 3.
  Set their Tag property to respectively 1, 2 and 3.
 
 4.
  Select them all.
 
 5.
  Double-click the OnClick event:
 
void __fastcall TForm1::Button3Click(TObject *Sender)
{
    ShowMessage("You clicked on Button #" + IntToStr
        (((TButton *)Sender)->Tag));
}
 
Hints
 
C++Builder 4 or greater includes support for action lists that simplify the process of code sharing.

C++Builder Developer's Network
Copyright © Yoto Yotov



Acquiring image from ProHosting Banner Exchange