我知道在本窗体成批修改控件属性的方法是:
for i:=1 to n do
Tlabel(FindComponent('label' + inttostr(i))).Visible := true;那么,如果我要在其他的窗体里,比如说主窗体MAINFORM里成批修改FORM1里控件的属性,应该怎么写呢?

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      i,j:integer;
    begin
      i:=form2.ComponentCount;
      for j:=0 to i-1 do
      begin
        if form2.Components[j].ClassName='TLabel' then
          (form2.Components[j] as TLabel).Caption:='csdn';
      end;
    end;
      

  2.   

    试一下这种:
    var
      i:integer;
    begin
      for i:=0 to Form4.ComponentCount-1 do
      begin
        (Form4.Components[i] as TLabel).Visible :=True;
      end;
    end;
      

  3.   

    procedure ModifiedLabel(AOwner:TComponent);
    var
      i:integer;
    begin
      for i=0 to AOwner.ComponentCount-1 do
      begin
        if Components[i] is TLabel then
           (Components[i] as TLabel).Visible=True;
      end;
    end;以后调用就可以啦:节器
      

  4.   

    那就查找TForm,if (Object AS TForm).Name<> 'MainForm' then
                      (Object AS TForm).visible:=true;
      

  5.   

    各位的办法,都是不加选择的修改所有的同类型控件属性,我现在的情况是,FORM2里有两套SHAPE控件,一套名子为LIGHT1---LIGHT12,一套名字为SHAPE1---SHAPE12,而我现在只想修改名字为SHAPE N 的一套,如果按各位的方法,是不是要不加选择的把LIGHT N 也给修改了呢?
    所以我希望使用:
    for i:=1 to n do
    Tlabel(FindComponent('label' + inttostr(i))).Visible := true;
    这样的能把控件名字加进去进行识别的办法,怎么修改呢?
      

  6.   

    那就用
    procedure TForm1.Button1Click(Sender: TObject);
    var
      i,j:integer;
    begin
      i:=form2.ComponentCount;
      for j:=0 to i-1 do
      begin
        if pos('shape',form2.Components[j].Name)>0 then
           (form2.Components[j].Name as TLabel).visible:=true;
      end;
    end;
      

  7.   

    我还是把代码帖出来吧,你们看看哪里的毛病?
    错误提示为:
    Operator not applicable to this operand type
    运算符不使用于这一运算对象类型procedure Tmainform.Timer1Timer(Sender: TObject);
    var i:integer;
    shapeshow:single;
    j:integer;
    tt:integer;
    begin
    shapeshow:=moilh[i]/2600;
    tt:=showallform.ComponentCount;
    for j:=1 to tt do
      begin    //错误就出在这一行
        if pos('shape'+inttostr(j),showallform.Components[j-1].Name)>0 then
           begin
           (showallform.Components[j-1].Name as tshape).top:=round(8+87*(1-shapeshow));
           (showallform.components[j-1].name as tshape).height:=round(87*shapeshow);
           end;
      end;
    end;
      

  8.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      i,j:integer;
    begin
      i:=form2.ComponentCount;
      for j:=0 to i-1 do
      begin
        if pos('shape',form2.Components[j].Name)>0 then
           (form2.Components[j] as TLabel).Visible:=true;
      end;
    end;
      

  9.   

    使用componets,componentcount等控件需要在USES里添加什么么?
    为什么我一用form2.components,程序就编译错误??