我想在主窗体的程序里,成批的给其他窗体控件的属性赋值,比如FORM2里有许多LABEL控件,有些名字为LABEL1-----N,有些为其他名字,现在想要给这些名字为LABEL N的一批控件用FOR循环来赋值,该怎样写这段代码?
注意以上操作都是在FORM1里的,而不是在FORM2里。

解决方案 »

  1.   

    use unit2 
     for i:=0 to form2.ComponentCount-1 do
      begin
          if form2.Components[i] is TLabel then
             Tlabel(form2.components[i]).Caption:='sdf';
      end;
      

  2.   

    for i :=0 to Form2.Componentcount -1 do
      if Form2.Componets[i].ClassType =TLabel then
        TLable(Form2.Componets[i]).caption :='';
      

  3.   

    请问二位,如果FORM2上还有名字为WOSHI的LABEL控件,怎么办?是不是要连WOSHI的属性也要改了?可是我不想改它!怎么做?
      

  4.   

    if Form2.Componets[i].ClassType =TLabel and pos('LABEL',TLable(Form2.Componets[i]).name)>0 then
      

  5.   

    使用componets,componentcount等控件需要在USES里添加什么么?
      

  6.   

    var
      i : integer;
    begin
      for i := 0 to ComponentCount-1 do
        begin
          if( Components[ i ] is TEdit )then
          begin
            (Components[ i ] as TEdit).Text :=‘哈哈哈哈’
         end;
      end;
    end;不知道有没帮助
      

  7.   

    为什么我一用form2.components,程序就编译错误??
      

  8.   

    form2.components 是不是忘记加下标,不过不可能。随便说一下