UserForm.Component Property

Applies to TestComplete 15.70, last modified on December 17, 2024

Description

Use the Component property to obtain the form component specified by its index. This property lets you obtain the component that is located directly on the form as well as on the container component (for example, panel or group box). To determine the total number of form components, use the ComponentCount property.

Declaration

UserForm.Component(Index)

Read-Only Property A user form component object
Index [in]    Required    Integer    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

Index

The index of the desired form component. The index is zero-based: the first component has index 0, the second - 1, and so on. The index of the last component is ComponentCount - 1.

Property Value

A form component that has the specified index.

Remarks

If you use Python or DelphiScript, you should enclose the parameter of the Component property in square brackets: Component[Index].

The Component property is similar to the ChildControl property, but the Component property is more “powerful”. The main difference between these properties is that ChildControl is used to access components that are situated directly on the form, whereas Component lets you access all form components -- those that are situated on the form as well as those that are situated on the container components, such as panels and group boxes. Also, the ChildControl property lets you access all kinds of components except for those that do not occupy a place on the form, such as dialogs, whereas the Component property can be used to enumerate all components, including dialogs.

Note that you can also obtain the form component by its name:

  • Via the UserForm object by directly specifying the component name.
  • Using the ChildControlByName property (this can be used to access all components except dialogs and those components that are not situated directly on the form).
  • Using the ComponentByName property.

Example

The following code obtains the form’s TOpenDialog component by its index, modifies its properties and displays the dialog:

JavaScript, JScript

function Test()
{

  var TestForm, Component
  // Obtains the user form
  TestForm = UserForms.FormByName("TestForm");

  // Obtains the component by its index
  Component = TestForm.Component(0);

  // Sets the component properties
  Component.InitialDir = "C:\\Program Files";
  Component.Filter = "Text files (*.txt)|*.TXT";

  // Displays the user form
  TestForm.Show();
  // Displays the dialog component
  Component.Execute();

  …
}

Python

def Test():
  # Obtains the user form
  TestForm = UserForms.FormByName["TestForm"]
  # Obtains the component by its index
  Component = TestForm.Component[0]
  # Sets the component properties
  Component.InitialDir = "C:\\Program Files"
  Component.Filter = "Text files (*.txt)|*.TXT"
  # Displays the user form
  TestForm.Show()
  # Displays the dialog component
  Component.Execute()
  # ...

VBScript

Sub Test

  Dim TestForm, Component

  ' Obtains the user form
  Set TestForm = UserForms.FormByName("TestForm")

  ' Obtains the component by its index
  Set Component = TestForm.Component(0)

  ' Sets the component properties
  Component.InitialDir = "C:\Program Files"
  Component.Filter = "Text files (*.txt)|*.TXT"

  ' Displays the user form
  TestForm.Show
  ' Displays the dialog component
  Call Component.Execute

  …
End Sub

DelphiScript

procedure Test();
var TestForm, Component;
begin

  // Obtains the user form
  TestForm := UserForms.FormByName('TestForm');

  // Obtains the component by its index
  Component := TestForm.Component(0);

  // Sets the component properties
  Component.InitialDir := 'C:\Program Files';
  Component.Filter := 'Text files (*.txt)|*.TXT';

  // Displays the user form
  TestForm.Show;
  // Displays the dialog component
  Component.Execute;

  …
end;

C++Script, C#Script

function Test()
{

  var TestForm, Component
  // Obtains the user form
  TestForm = UserForms["FormByName"]("TestForm");

  // Obtains the component by its index
  Component = TestForm["Component"](0);

  // Sets the component properties
  Component["InitialDir"] = "C:\\Program Files";
  Component["Filter"] = "Text files (*.txt)|*.TXT";

  // Displays the user form
  TestForm["Show"]();
  // Displays the dialog component
  Component["Execute"]();

  …
}

See Also

ChildControl Property
ChildControlByName Property
ChildControlCount Property
ComponentByName Property
ComponentCount Property

Highlight search results