我用了n个Label组件(或者Edit组件),名称分别位Label1,Label2,.....Labeln;请问如何批量的修改其属性呢(如Visible属性)?还请给个例子,谢了。

解决方案 »

  1.   

    for i:=1 to 10 do
    begin
      tedit(findcomponent('edit'+inttostr(i))).visible:=true;
    end;
      

  2.   

    findcomponent('字符串')返回以字符串为名字的控件
    用tedit强制类型转换就可以了。
      

  3.   

    for i:=ComponentCount-1 downto 0 do
    begin
      if Components[i] is TLabel then
         TLabel(Components[i]).Visible:=True;
    end;
      

  4.   

    for i:=ComponentCount-1 downto 0 do
    begin
      if Components[i] is TLabel then
         (Components[i] as TLabel).Enable:=True;
    end
      

  5.   

    你们都是错的,如果是在容器组件,就不能设置了。我的递归清空文本。改下就有了。//=====yeeyee S & T  易一科技=====
    procedure TFormCYBase.ClearText(AControl:TWinControl);
    var
      I: Integer;
    begin
      for I := 0 to AControl.ControlCount - 1 do    // Iterate
      begin
        //需清空处理控件
        if AControl.Controls[i] is TCustomEdit then
        begin
          (AControl.Controls[i] as TCustomEdit).Text:='';
        end;
        if AControl.Controls[i] is TCustomComboBox then
        begin
          (AControl.Controls[i] as TCustomComboBox).ClearSelection;
        end;
        //可以 作为 父亲的控件处理事件。
        if AControl.Controls[i] is TCustomControl  then
        begin
          ClearText(AControl.Controls[i] as TCustomControl);
        end;
      end;
    end;procedure TFormCYBase.BitBtn1Click(Sender: TObject);
    begin
      ClearText(self);
    end;
      

  6.   

    你们都是错的,如果是在容器组件,就不能设置了。
    ------------------------------------------------
    谁说容器组件内的控件就不能用FindComponent了?只要在form内都可以,加不加self无所谓
    tedit(FindComponent('edit1')).Text:='';
    这个edit1的parent是一个panel,照样可以
      

  7.   

    问个问题,
    Tcustomcontrol为什么是父控件?因为其它自定控件都从它承继?用强制转换会快点 as 操作符比较慢
      

  8.   

    delphi深度历险 里面有相关的例子
      

  9.   

    procedure TMainForm.M1Click(Sender: TObject);
    var
      i: integer;
      propinfo:ppropinfo;参考一下
    begin
      //访问form上所有组件
      for i:=0 to componentcount-1 do
      begin
        propinfo:=getpropinfo(components[i].classinfo,'color');
        if propinfo<>nil then
          setordprop(components[i],propinfo,clblue);
      end;end;