Re: how to check if a button is clicked
Posted by webmaster Guido on June 16, 2003 at 18:15:50:
In Reply to: how to check if a button is clicked posted by savagerider on June 14, 2003 at 10:05:27:
: how to check if a button is clicked ?
I suppose that you have several buttons that share a single event handler, and that you want to find out which button was clicked? Please, ask again if I'm wrong.
Here is an example where three buttons have the same procedure Button1Click assigned as their OnClick handler:
procedure TForm1.Button1Click(Sender: TObject); begin if Sender = Button1 then Label1.Caption := 'Button1 was clicked' else if Sender = Button2 then Label1.Caption := 'Button2 was clicked' else if Sender = Button3 then Label1.Caption := 'Button3 was clicked' else Label1.Caption := 'Another component was clicked'; end;
The last line is only reached, if another component is clicked that is also "connected" to the event handler Button1Click.
[ DelphiLand: free Delphi source code, tips, tutorials ]