如何用一个循环控制n个相同控件的属性?
我有n个Tlabel:Label1,Label2,Label3,...Labeln
请问怎么使用循环控制上面Labels的某个属性?

解决方案 »

  1.   

    for i:=1 to n do
      with tlabel(findcomponent('label'+inttostr(i))) do
         caption:=inttostr(i);
      

  2.   

    procedure Tform1.Button1Click(Sender: TObject);
    var
      i:integer;
    begin
      with form1 do
        for i:=0 to ComponentCount-1 do
        begin
          if (Components[i] is Tlabel) then
          begin
            (Components[i] as Tlabel).cattion:=inttostr(i);
          end;
       end;
    end;
      

  3.   

    for i:= 0 to aForm.ComponentCount- 1 do
      begin
        if aForm.Components[i] is TLabel then
        begin
          (aForm.Components[i] as TLabel).Text:= '';//属性控制
        end;
      end;
      

  4.   

    for i:=0 to componentcount-1 do
     if components[i]is tedit then
    begin
    end;
      

  5.   

    首先同意楼上的。
    可以把这些控件装到一个容器中,例如groupbox
    然后
    for i:=0 to GroupBox.ControlCount-1 do
    begin
      if GroupBox.Controls[i].ClassType=TLable then
      TLabel(GroupBox.Controls[i]).Caption:='ok';
    end;
      

  6.   

    procedure Tform1.Button1Click(Sender: TObject);
    var
      i:integer;
    begin
      with form1 do
        for i:=0 to ComponentCount-1 do
        begin
          if (Components[i] is Tlabel) then
          begin
            (Components[i] as Tlabel).cattion:=inttostr(i);
          end;
       end;
    end;