unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; Edit2: TEdit; Label1: TLabel; procedure FormCreate(Sender: TObject); private procedure MouseTagAppMessage(var Msg: TMsg; var Handled: Boolean); public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}{ TForm1 }procedure TForm1.MouseTagAppMessage(var Msg: TMsg; var Handled: Boolean); begin if Msg.message = WM_LBUTTONDOWN then Label1.Caption := IntToStr(FindVCLWindow(Mouse.CursorPos).Tag);end;procedure TForm1.FormCreate(Sender: TObject); begin Application.OnMessage := MouseTagAppMessage; Button1.Tag := 3; Edit1.Tag := 1; Edit2.Tag := 2; Label1.Tag := 4; end;end.能处理TWinControl的后代!
写一个通用过程,只要把它塞给相应的控件事件处理就可以用了:: procedure ControlTag(Sender: TObject); begin if Sender is TWinControl then ShowMessage(IntToStr((Sender as TWinControl).Tag)); end;
begin
ShowMessage(IntToStr((Sender as TButton).Tag));
end;
begin
if Sender is TWinControl then
ShowMessage(IntToStr((Sender as TWinControl).Tag));
end;
ShowMessage(IntToStr(ActiveControl.Tag)):
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Label1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
procedure MouseTagAppMessage(var Msg: TMsg; var Handled: Boolean); public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}{ TForm1 }procedure TForm1.MouseTagAppMessage(var Msg: TMsg; var Handled: Boolean);
begin
if Msg.message = WM_LBUTTONDOWN then Label1.Caption:=IntToStr(FindVCLWindow(Mouse.CursorPos).Tag);end;procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := MouseTagAppMessage;
Button1.Tag := 3;
Edit1.Tag := 1;
Edit2.Tag := 2 ;
Label1.Tag:=4;
end;procedure TForm1.Label1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
beginend;end.能处理TWinControl的后代!
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
private
procedure MouseTagAppMessage(var Msg: TMsg; var Handled: Boolean); public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}{ TForm1 }procedure TForm1.MouseTagAppMessage(var Msg: TMsg; var Handled: Boolean);
begin
if Msg.message = WM_LBUTTONDOWN then Label1.Caption := IntToStr(FindVCLWindow(Mouse.CursorPos).Tag);end;procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := MouseTagAppMessage;
Button1.Tag := 3;
Edit1.Tag := 1;
Edit2.Tag := 2;
Label1.Tag := 4;
end;end.能处理TWinControl的后代!
procedure ControlTag(Sender: TObject);
begin
if Sender is TWinControl then
ShowMessage(IntToStr((Sender as TWinControl).Tag));
end;