delphi Sender和Tag的用法1

时间:2023-12-19 19:44:20
Sender和Tag的用法  在它们共同的OnClick事件下返回单击的那个按钮的标题
delphi Sender和Tag的用法1
delphi Sender和Tag的用法1
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages,
System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1:
TButton;
    Button2:
TButton;
    Button3:
TButton;
    Button4:
TButton;
    Button5:
TButton;
    Button6:
TButton;
    Button7:
TButton;
    procedure
Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R
*.dfm}

procedure
TForm1.Button1Click(Sender: TObject);
begin
  if Sender is
TButton then
     ShowMessage((Sender
as TButton).Caption);
end;