建立一个类似与 LabelsClick(sender :object) 的过程。在你动态建立这些Label的时候,把他们的
Label1.OnClick := LabelsClick然后在这个过程中判断caption.我想以下就没有什么难的了点?

解决方案 »

  1.   

    procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
      var
        i:integer;
    begin
        for i:=0 to ComponentCount-1 do
        begin
        if (Components[i] is Tlabel) then
        showmessage('1');
        end;
    end;
      

  2.   

    我的意思是:
    如我创建了三个Label
    for i:=1 to 3 do
    begin
    mainform.vLabel[i]:=TLabel.Create(Application);
    mainform.vLabel[i].Name:='Label'+inttostr(17+i);
    mainform.vLabel[i].Parent:=mainform.Panel1;
    mainform.vLabel[i].caption:=stringname;//stringname每次的字符都不一样
    mainform.vLabel[i].OnMouseDown := mainform.LabellMouseDown;
    //我在程序运行后,在点击这三个Label中的任何一个时,我怎么知道这个Label的caption是什么呢?
    end;
      

  3.   

    Best_thinker() 说的应该可以
    然后(Sender as TLabel).Caption
      

  4.   

    showmessage(TLabel(sender)).caption)即可
      

  5.   

    MyLabel.OnClick:=Label1.OnClick();procedure TForm1.Label1Click(Sender: TObject);
    begin
      Showmessage((sender as tlabel).Caption);
    end;
    就可以了
      

  6.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      AppEvnts, StdCtrls, Buttons;type
      TForm1 = class(TForm)
        Label1: TLabel;
        Label2: TLabel;
        Label3: TLabel;
        Label4: TLabel;
        ApplicationEvents1: TApplicationEvents;
        BitBtn1: TBitBtn;
        procedure ApplicationEvents1Message(var Msg: tagMSG;
          var Handled: Boolean);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
      var Handled: Boolean);
    Var
      P:TPoint;
      cControl:TControl;
    Begin
      if (Msg.message =WM_LBUTTONDOWN)Then
      Begin
          GetCursorPos(P);
          cControl:=FindDragTarget(P, True);
          if cControl.ClassName ='TLabel' Then
            Showmessage(cControl.Name);
      End;
    end;end.
      

  7.   

    I test it, it work ok.I can't input Chinese word.
      

  8.   

    I test it, it work ok.I can't input Chinese word.
      

  9.   

    procedure LabellMouseDown(sender :object)
    begin
      showmessage((Sender as TLabel).Caption)
    end;