请问一下,怎么得到当前点击的控件的Tag值呀?

TangDY 2003-08-23 05:38:37
高手:

小弟想请教一下怎么用程序动态得到我当前点击的控件的Tag值呀?



请高手给出实例,小弟高分相送~
...全文
44 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
cnhgj 2003-08-24
  • 打赏
  • 举报
回复
showmessage(inttostr(TComponent(form1.ActiveControl).tag));
knock 2003-08-24
  • 打赏
  • 举报
回复
写一个通用过程,只要把它塞给相应的控件事件处理就可以用了::
procedure ControlTag(Sender: TObject);
begin
if Sender is TWinControl then
ShowMessage(IntToStr((Sender as TWinControl).Tag));
end;
madyak 2003-08-23
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
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的后代!
madyak 2003-08-23
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
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);
begin

end;

end.

能处理TWinControl的后代!
zhoutian618 2003-08-23
  • 打赏
  • 举报
回复
if Activecontrol<>nil then
ShowMessage(IntToStr(ActiveControl.Tag)):
leonkim 2003-08-23
  • 打赏
  • 举报
回复
procedure TForm1.Button1Click(Sender: TObject);
begin
if Sender is TWinControl then
ShowMessage(IntToStr((Sender as TWinControl).Tag));
end;
DWGZ 2003-08-23
  • 打赏
  • 举报
回复
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(IntToStr((Sender as TButton).Tag));
end;

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧