Salvador
Salvador

Reputation: 16482

Why the ComponentCount property of my TGroupBox returns 0?

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

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

but the ComponentCount returns always 0, what i'm missing?

Upvotes: 9

Views: 5932

Answers (2)

MajidTaheri
MajidTaheri

Reputation: 3983

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

Upvotes: 0

RRUZ
RRUZ

Reputation: 136431

The ComponentCount property is for retrieve the number of components owned by a component, to iterate over all the children controls you must use the ControlCount and Controls properties.

Upvotes: 18

Related Questions