如何获取我自己创建的控件的名字呀。

解决方案 »

  1.   

    名字在你创建的时候就定了啊。显示出来的是caption属性。
      

  2.   

    btn1 := TButton.Create(self);// btn1就是这个动态创建的控件的name
      

  3.   

    unit MainUnit;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, IniFiles, ExtCtrls, StdCtrls, Buttons;type
      TForm1 = class(TForm)
        Image1: TImage;
        BitBtn1: TBitBtn;
        procedure FormCreate(Sender: TObject);
        procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
        procedure BitBtn1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        procedure BOnclick(Sender:TObject);
      end;var
      Form1: TForm1;
      IniFile:TIniFile;
      buttonPosition:Array[1..50] of record
         top:integer;
         left:integer;
      end;
      button:Array[1..20] of TBitbtn;
      buttonname:Tbitbtn;
    implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    var
        count,i:integer;
        buttons:string;
        bitmap:Tbitmap;
    begin
        bitmap:=Tbitmap.Create;
        bitmap.LoadFromFile(ExtractFilePath(application.ExeName)+'mail.bmp');
        IniFile:=TIniFile.Create(ExtractFilePath(application.ExeName)+'position.ini');
        count:=20;
        for i:=1 to 20 do
        begin
          buttons:='button'+inttostr(i);
          buttonposition[i].top:=IniFile.ReadInteger(buttons,'top',-1);
          buttonposition[i].left:=IniFile.ReadInteger(buttons,'left',-1);
          button[i]:=tBitbtn.Create(self);
          button[i].Top :=buttonposition[i].top;
          button[i].Left:=buttonposition[i].left;
          button[i].Caption :='话筒'+inttostr(i);
          button[i].Layout :=blGlyphtop;
          button[i].Glyph :=bitmap;
          button[i].Height :=60;
          button[i].Name :='button'+inttostr(i);
          button[i].OnClick :=BOnclick;
          button[i].Parent :=form1;
        end;
    end;procedure TForm1.BOnclick(Sender:TObject);
    begin
    end;
    procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
        buttonname.Top :=y;
        buttonname.Left :=x;
    end;procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
       buttonname :=self.BitBtn1;
    end;end.我想要点击一个任意一个我所创建的按钮后,在窗体上点右键,使它就移到当前位置。如何实现呀。
      

  4.   

    楼主想做什么 ?
    结楼上朋友的:
    btn1 := TButton.Create(self);// btn1就是这个动态创建的控件的name获取:   s := Btn1.Name ;楼主想做什么 ?
      

  5.   

    “点击一个控件,然后在窗口任意位置点击右键,将该控件移到相因位置 “ 应该用消息吧, 这样以来要获得最近的 TBitBtn 的句柄,获得句柄简单,而怎样知道是最近点击的要写鼠标钩子 。  是这样还是我还没有搞清楚楼主的问题 ????
      

  6.   

    呵呵,wjlsmail(计算机质子)哥哥你肯定是想复杂了,我是这么理解的
    在这个函数里加东西就行了啊procedure TForm1.BOnclick(Sender:TObject);
    begin
      buttonname := TButton(Sender); 
    end;
      

  7.   

    :) 的确楼上大哥这个楼主现在已经好了,楼主那个贴子中 laihecongxi(兴哥) 给了非常简单高效的方法 :)http://expert.csdn.net/Expert/topic/1277/1277561.xml?temp=3.324527E-02
      

  8.   

    偶认为你应该建个链表保存它,用的时候再取出来就成了
    如果控件类型不清楚可以判断一下类型嘛
    还有,控件的tag和hint属性都可以记录一个标识(偶也是刚学得)