UserForm.ChildControlCount Property

Applies to TestComplete 14.10, last modified on June 5, 2019

Description

Use the ChildControlByName property to determine the total number of child controls on a form. You can use this property along with ChildControl to enumerate through the form’s child controls.

In general, a control is a component that occupies a place on a form. For example, a button is a control, and a dialog is not. The ChildControlCount property only returns the number of form controls, that is, it does not include components that do not occupy a place on the form, such as dialogs. To obtain a total number of form components, including dialogs, use the ComponentCount property.

Declaration

UserForm.ChildControlCount

Read-Only Property Integer

Applies To

The property is applied to the following object:

Property Value

An integer value that means the total number of child controls on a form.

Remarks

The ChildControlCount property is similar to the ComponentCount property. The difference in these properties is that ChildControlCount only includes components that are situated directly on the form, whereas ComponentCount includes all form components -- those that are situated on the form as well as those that are situated on the form’s container components, such as panels and group boxes. Also, the ChildControlCount property does not include components that do not occupy a place on a form, such as dialogs, whereas the ComponentCount property takes into account all components, including dialogs.

Example

The following example demonstrates how you can use the ChildControlCount property to enumerate through the form’s child controls and post their names to the test log:

JavaScript, JScript

function Test()
{
  var TestForm, Count;
  // Obtains the user form
  TestForm = UserForms.TestForm;
  // Determines the total amount of child controls on the form
  Count = TestForm.ChildControlCount;

  // Checks if the form contains at least one child control
  if (Count > 0)
    {
    Log.AppendFolder("The form contains the following controls:");
    // Iterates through the form’s child controls and posts their names to the log
    for (var i = 0; i < Count; i++)
      Log.Message(TestForm.ChildControl(i).Name);
    Log.PopLogFolder();
    }
  else
    Log.Message("The form does not contain any controls.");
}

Python

def Test():
  # Obtains the user form
  TestForm = UserForms.TestForm
  # Determines the total amount of child controls on the form
  Count = TestForm.ChildControlCount
  # Checks if the form contains at least one child control
  if Count > 0:
    Log.AppendFolder("The form contains the following controls:");
    # Iterates through the form's child controls and posts their names to the log
    for i in range(0, Count):
      Log.Message(TestForm.ChildControl[i].Name)
    Log.PopLogFolder()
  else:
    Log.Message("The form does not contain any controls.")

VBScript

Sub Test

  Dim TestForm, Count
  ' Obtains the user form
  Set TestForm = UserForms.TestForm
  ' Determines the total amount of child controls on the form
  Count = TestForm.ChildControlCount

  ' Checks if the form contains at least one child control
  If Count > 0 Then
    Log.AppendFolder("The form contains the following controls:")
    ' Iterates through the form’s child controls and posts their names to the log
    For i = 0 To Count - 1
      Log.Message(TestForm.ChildControl(i).Name)
    Next
    Log.PopLogFolder
  Else
    Log.Message("The form does not contain any controls.")
  End If

End Sub

DelphiScript

procedure Test();
var TestForm, Count, i;
begin
  // Obtains the user form
  TestForm := UserForms.TestForm;
  // Determines the total amount of child controls on the form
  Count := TestForm.ChildControlCount;

  // Checks if the form contains at least one child control
  if Count > 0 then
    begin
    Log.AppendFolder('The form contains the following controls:');
    // Iterates through the form’s child controls and posts their names to the log
    for i := 0 to Count - 1 do
      Log.Message(TestForm.ChildControl[i].Name);
    Log.PopLogFolder();
    end
  else
    Log.Message('The form does not contain any controls.');
end;

C++Script, C#Script

function Test()
{
  var TestForm, Count;
  // Obtains the user form
  TestForm = UserForms["TestForm"];
  // Determines the total amount of child controls on the form
  Count = TestForm["ChildControlCount"];

  // Checks if the form contains at least one child control
  if (Count > 0)
    {
    Log["AppendFolder"]("The form contains the following controls:");
    // Iterates through the form’s child controls and posts their names to the log
    for (var i = 0; i < Count; i++)
      Log["Message"](TestForm["ChildControl"](i)["Name"]);
    Log["PopLogFolder"]();
    }
  else
    Log["Message"]("The form does not contain any controls.");
}

See Also

UserForm.ChildControl Property
UserForm.Component Property
UserForm.ComponentCount Property

Highlight search results