How can I see who triggered an action in Delphi?

前端 未结 7 1339
别那么骄傲
别那么骄傲 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:58

    Try using the ActionComponent property:

    Stores the client component that caused this action to execute.

    Use ActionComponent to discern which client component caused this action to execute. For example, examine ActionComponent from an OnExecute event handler if you need to know what user action triggered this action.

    When the user clicks a client control, that client sets ActionComponent before calling the action's Execute method. After the action executes, the action resets ActionComponent to nil.

    For example:

      ShowMessage( (Sender as TAction).ActionComponent.Name );
    

    Using this I get "Button1" and "Button2" when I click the first and second button respectively.

提交回复
热议问题