UserForm.ComponentByName Property

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

Description

Use the ComponentByName property to obtain the form component specified by its name. 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).

Declaration

UserForm.ComponentByName(Name)

Read-Only Property A user form component object
Name [in]    Required    String    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

Name

The name of the desired form component.

Property Value

A form component that has the specified name.

Remarks

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

The ComponentByName property is similar to the ChildControlByName property, but the ComponentByName property is more “powerful”. The main difference between these properties is that the ChildControlByName is used to access components that are situated directly on the form, whereas ComponentByName 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 ChildControlByName property lets you access all kinds of components except those that do not occupy a place on the form, such as dialogs, whereas the ComponentByName property can be used to access all components, including dialogs.

Note that you can also obtain the form component via the UserForm object, by directly specifying the component name.

Example

The following code obtains the form’s TOpenDialog component by its name, 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 name
  Component = TestForm.ComponentByName("OpenDialog");

  // Modifies 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 name
  Component = TestForm.ComponentByName["OpenDialog"]
  # Modifies 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 name
  Set Component = TestForm.ComponentByName("OpenDialog")

  ' Modifies 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 name
  Component := TestForm.ComponentByName('OpenDialog');

  // Modifies 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 name
  Component = TestForm["ComponentByName"]("OpenDialog");

  // Modifies 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

ChildControlByName Property
Component Property
ComponentCount Property

Highlight search results