Why does the ComponentCount property of my TGroupBox return 0?

I have a TGroupBox with several components inside, I'm trying to set the Enabled property of all components that are inside the GroupBox this way

  for i := 0 to GroupBox1.ComponentCount -1 do if (GroupBox1.Components[i]) is TWinControl then TWinControl(GroupBox1.Components[i]).Enabled:=False; 

but ComponentCount always returns 0, what am I missing?

+6
source share
2 answers

The ComponentCount property is used to get the number of components owned by the component, to repeat all child elements , you must use the ControlCount and Controls properties.

+14
source
 for i := 0 to GroupBox1.ControlCount - 1 do if (GroupBox1.Controls[i]) is TWinControl then TWinControl(GroupBox1.Controls[i]).Enabled:=False; 
-1
source

Source: https://habr.com/ru/post/911908/


All Articles