Author: Tomas Rutkauskas
I need to put a lot of TSpeedButtons into a GroupBox (for example 20). For each
button I set a GroupIndex. Is it possible to control what button was pressed
without writing a SpeedButtonClick procedure for each button?
Answer:
The OnClick method passes the Sender in as a TObject. You can hook all the buttons
up to the same OnClick methods and check to see which button was clicked something
like this:
1 procedure TForm1.SpeedButton1Click(Sender: TObject);
2 begin3 if Sender is TSpeedButton then4 with Sender as TSpeedButton do5 begin6 case GroupIndex of7 1: ;
8 2: ;
9 3: ;
10 end;
11 end;
12 end;
This is assuming the GroupIndex of each button is unique.