有14个Label,一个计数器count=1
如何通过count来调用这14个label
label[count]不行
form1.labels[count]也不行怎么办?

解决方案 »

  1.   

    定义一个数组将label赋给他们.再操纵数组
      

  2.   

    你这样肯定不行,你要在程序中声明label控件数组
    var
    Elabel :array[1..12] of Tlabel;
    i:integer;
    begin
      for i:=1 to 12 do
      begin
        Elabel[i]:=Tlabel.Create(Self);
        Elabel[i].Parent:=Form1;
        Elabel[i].Top:=i*20;
        Elabel[i].Left:=20;
        Elabel[i].Caption:='Elabel'+inttostr(i);
      end;
    end;
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      i:integer;
    begin
      for i:=0 to ControlCount-1 do
        begin
          if Controls[i].ClassType=TLabel then
            begin
              //TLabel(Controls[i]).Caption:='ArrayLabel['+IntToStr(i)+']';
            end;
        end;
    end;