RAD Studio |  |

Using the Sender Parameter
See Also
Collapse All

In an event handler, the Sender parameter indicates which component received the event and therefore called the handler. Sometimes it is useful to have several components share an event handler that behaves differently depending on which component calls it. You can do this by using the Sender parameter in an if...then...else statement. For example, the following code displays the title of the application in the caption of a dialog box only if the OnClick event was received by Button1.

Copy Code

    procedure TMainForm.Button1Click(Sender: TObject);
    begin
    if Sender = Button1 then
      AboutBox.Caption := 'About ' + Application.Title
    else
      AboutBox.Caption := '';
    AboutBox.ShowModal;
    end;

See Also

Working with Events and Event Handlers

Associating an Event with an Existing Event Handler

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!