How can I see who triggered an action in Delphi?

前端 未结 7 1338
别那么骄傲
别那么骄傲 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 13:08

    set the Tag of the buttons as 1, 2, ... etc and then:

    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Button1.OnClick := ButtonClick;
      Button2.OnClick := ButtonClick;
    end;
    
    procedure TForm1.ButtonClick(Sender: TObject);
    begin
      if Sender is TButton then
      begin
        Caption := 'Button: ' + IntToStr(TButton(Sender).Tag);
      end;  
    end;
    

提交回复
热议问题