RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TWinControl.ControlCount Property

Returns the number of child controls.

Pascal
property ControlCount: Integer;
C++
__property int ControlCount;

Read ControlCount when iterating over all the children of this control. The children of the control are listed in the Controls property array. 

ControlCount is a read-only property.

Note: The value of ControlCount is always 1 greater than the highest Controls index, because the first Controls index is 0.
 

C++ Examples: 

 

/*
This example uses an updown control and a group box on a 
form, with several controls contained within the group box.
When the updown control or is clicked, the controls within 
the group box are moved in the appropriate direction.
*/
void __fastcall TForm1::UpDown1Click(TObject *Sender, TUDBtnType Button)
{
  int I;
  TControl *ChildControl;

  for (I = 0; I < GroupBox1->ControlCount; I++)
  {
    ChildControl = GroupBox1->Controls[I];
    if (Button == btNext) 
      ChildControl->Top = ChildControl->Top + 15;
    else
      ChildControl->Top = ChildControl->Top - 15;
  }
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  const TColor colorarray[5] = {clYellow, clGreen, clBlue, clLime, clFuchsia};
  GroupBox1->Brush->Color = clRed;
  for (int i = 0; i < GroupBox1->ControlCount; i++)
    ((TWinControl *)GroupBox1->Controls[i])->Brush->Color = colorarray[i];
}

 

Delphi Examples: 

{
This example uses an updown control and a group box on a 
form, with several controls contained within the group box.
When the updown control or is clicked, the controls within 
the group box are moved in the appropriate direction.
}
procedure TForm1.FormCreate(Sender: TObject);
var
  I: Integer;
const
  colorarray : Array[0..4] of TColor = (clYellow, clGreen, clBlue, clLime, clFuchsia);
begin
   GroupBox1.Brush.Color := clRed;
  for I:= 0 to GroupBox1.ControlCount -1 do
  begin
    TWinControl(GroupBox1.Controls[I]).Brush.Color := colorarray[I];
  end;
end;

procedure TForm1.UpDown1Click(Sender: TObject; Button: TUDBtnType);
var
  I: Integer;
  ChildControl: TControl;
begin
  for I:= 0 to GroupBox1.ControlCount -1 do
  begin
    ChildControl := GroupBox1.Controls[I];
    if Button = btNext then
      ChildControl.Top := ChildControl.Top + 15
    else
      ChildControl.Top := ChildControl.Top - 15;
  end;
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!