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?
-
- Start a new application.
-
- Add three (3) Buttons.
-
- Set their Tag property to respectively 1, 2 and 3.
-
- Select them all.
-
- 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