本帖最后由 cggong 于 2011-08-24 22:11:30 编辑

解决方案 »

  1.   

    var
       _Label:TLabel;
       i:integer;
    begin
    For i:=1 to 4 do 
    if FindComponent('Label'+inttostr(I)) <> nil then
    begin
      _Label:=FindComponent('Label'+inttostr(I))as TLabel;
      _Label.Text:=inttostr(i);
    end;
    end;
      

  2.   

    var
      i,c: integer;
    begin
      c:=1;
      for i := 0 to self.ComponentCount - 1 do
      begin
        if self.Components[i] is TLabel then
        (self.Components[i] as TLabel).Caption := inttostr(c);
        inc(c);
      end;
    end;
      

  3.   

    如果那4个TLabel的名字没带数字序列号的,可以这样:var i:integer;
        Labels: Array[0..3] of TLabel;
    begin
      Labels[0]:=startLbl;//相当于Label1
      Labels[1]:=endLbl;//相当于Label2
      Labels[2]:=connLbl;//相当于Label3
      Labels[3]:=countLbl;//相当于Label4
      for i:=0 to 3 do Labels[i].Caption:= inttostr(i);
    end;
      

  4.   

    使用Controls或Components循环给数组赋值