How can I see who triggered an action in Delphi?

前端 未结 7 1357
别那么骄傲
别那么骄傲 2021-02-05 12:42

When a TAction event fires, the \"Sender\" is always the action itself. Usually that\'s the most useful, but is it somehow possible to find out who triggered the action\'s OnExe

7条回答
  •  你的背包
    2021-02-05 12:52

    Instead of actions, just use a click event. Set all buttons to use the same event handler. Ideally, NOT named after the first button (you can rename it).

    Here's the code:

    Procedure TMyForm.DestinationButtonClickHandlerThing(Sender: TObject); 
    begin
      if Sender = Btn_ViewIt then
      begin
        // View It
      end
      else if Sender = Btn_FaxIt then
      begin
        // Fax It
      end
      else if Sender = Btn_ScrapIt then
      begin
        // Scrap It
      end
      else 
        ....   // error
       ...
    end;
    

提交回复
热议问题