我想为它们的caption赋值.
谢谢关注!

解决方案 »

  1.   

    最好是动态生成你的Label控件吧。要不就要遍历窗口中的各个控件。
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      i : Integer;
    begin
      for i := 1 to 10 do
      begin
        if FindComponent('Label_' + IntToStr(i)) <> nil then
          TLabel(FindComponent('Label' + IntToStr(i))).Caption := 'text' + IntToStr(i)
      end;
    end;
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
    i : Integer;
    begin
    for i := self.componentcount-1 downto 0 do
    begin
    if self.components[i] is tlabel then
     TLabel(self.components[i]).Caption := 'text' + IntToStr(i)
    end;
    end;
      

  4.   

    如果要多次遍历的情况下,建议用这种方式:定义一个控件数组
    labelarr: array[1..10] of Tlabel;在窗口的CREATE事件中:
    labelarr[1]:=label1; labelarr[2]:=label2;  labelarr[3]:=label3.......这样处理后,在窗口的其它事件中可以直接操作这个数组, 遍历很方便的.
     
      

  5.   

    for i := 0 to (Sender as Tform).ComponentCount-1  do
      begin
        if (Sender as Tform).Components[i] is TLabel then
          TLabel ((Sender as Tform).Components[i]).caption := 'aaa';  end;