UserForm.ComponentCount Property

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

Use the ComponentCount property to determine the total number of components in the given form. You can use this property along with Component to enumerate through the form’s child controls.

Declaration

UserForm.ComponentCount

Read-Only Property Integer

Applies To

The property is applied to the following object:

Property Value

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

Remarks

The ComponentCount property is similar to the ChildControlCount 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 which 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 the 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 ComponentCount property to enumerate through the form’s components 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 the form’s components
  Count = TestForm.ComponentCount;

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

Python

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

VBScript

Sub Test

  Dim TestForm, Count
  ' Obtains the user form
  Set TestForm = UserForms.TestForm
  ' Determines the total amount of the form’s components
  Count = TestForm.ComponentCount

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

End Sub

DelphiScript

procedure Test();
var TestForm, Count, i;
begin
  // Obtains the user form
  TestForm := UserForms.TestForm;
  // Determines the total amount of the form’s components
  Count := TestForm.ComponentCount;

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

C++Script, C#Script

function Test()
{
  var TestForm, Count;
  // Obtains the user form
  TestForm = UserForms["TestForm"];
  // Determines the total amount of the form’s components
  Count = TestForm["ComponentCount"];

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

See Also

ChildControl Property
ChildControlCount Property
ComponentCount Property

Highlight search results