Is there any way to get all the controls on a container control?

后端 未结 6 463
小蘑菇
小蘑菇 2020-12-10 04:11

I\'ve got a form with a bunch of controls on it, and I wanted to iterate through all the controls on a certain panel and enable/disable them.

I tried this:



        
6条回答
  •  时光取名叫无心
    2020-12-10 04:31

    Here is a Delphi 2007 way:

    procedure TForm6.ModifyControl(const AControl: TControl; const value: Boolean);
    var
      i: Integer;
    begin
      if AControl=nil then Exit;
      if AControl is TWinControl then begin
        for i := 0 to TWinControl(AControl).ControlCount-1 do
          ModifyControl(TWinControl(AControl).Controls[i], value);
      end;
      Acontrol.Enabled := value;
    end;
    
    procedure TForm6.Button1Click(Sender: TObject); 
    begin 
      ModifyControl(Panel1, true);  // true or false
    end;
    

提交回复
热议问题