TObjectPicker Object

Applies to TestComplete 15.46, last modified on January 09, 2023

The TObjectPicker component is the target glyph. It is used to select objects on screen by dragging the component’s icon () to the desired object. The component is used, for instance, by the dialogs that create property or table checkpoints (using the target glyph users can choose the control whose properties will be checked). You can use the component for the same purpose: to allow users to specify the object whose properties will be processed. For instance, you can use the component to create dialogs for custom checkpoints.

The TObjectPicker component contains the OnObjectPicked event that is fired after the user selects an object. You can write an event handler for this event and perform the desired actions upon selecting the object. For instance, you can display the name of the selected window or control in a text box.

To obtain the name of the selected object, use the component’s PickedObjectName property. The following code demonstrates how you can obtain the name of the selected object and display it in a text box:

JavaScript, JScript

// This routine is called when the OnObjectPicked event occurs
function UserForm1_ObjectPicker1_OnObjectPicked(Sender)
{
  var objName;

  // Obtain the name of the selected object
  objName = UserForms.UserForm1.ObjectPicker1.PickedObjectName;

  // Displays the name in a text box
  UserForms.UserForm1.cxTextEdit1.Text = objName;
}

Python

# This routine is called when the OnObjectPicked event occurs
def UserForm1_ObjectPicker1_OnObjectPicked(Sender):

  # Obtain the name of the selected object
  objName = UserForms.UserForm1.ObjectPicker1.PickedObjectName

  # Displays the name in a text box
  UserForms.UserForm1.cxTextEdit1.Text = objName

VBScript

' This routine is called when the OnObjectPicked event occurs
Sub UserForm1_ObjectPicker1_OnObjectPicked(Sender)
  Dim objName

  ' Obtain the name of the selected object
  objName = UserForms.UserForm1.ObjectPicker1.PickedObjectName

  ' Displays the name in a text box
  UserForms.UserForm1.cxTextEdit1.Text = objName
End Sub

DelphiScript

// This routine is called when the OnObjectPicked event occurs
procedure UserForm1_ObjectPicker1_OnObjectPicked(Sender);
var
  objName : OleVariant;
begin
  // Obtain the name of the selected object
  objName := UserForms.UserForm1.ObjectPicker1.PickedObjectName;

  // Displays the name in a text box
  UserForms.UserForm1.cxTextEdit1.Text := objName;
end;

C++Script, C#Script

// This routine is called when the OnObjectPicked event occurs
function UserForm1_ObjectPicker1_OnObjectPicked(Sender)
{
  var objName;

  // Obtain the name of the selected object
  objName = UserForms["UserForm1"]["ObjectPicker1"]["PickedObjectName"];

  // Displays the name in a text box
  UserForms["UserForm1"]["cxTextEdit1"]["Text"] = objName;
}

To obtain the scripting interface to the selected object, use the eval (JavaScript, JScript, Python, C#Script, C++Script), Eval (VBScript) or Evaluate (DelphiScript) function (see the example below). After you obtain the object reference, you can call the object’s methods and set or get the values of the object’s properties. For instance, the following code demonstrates how you can obtain a reference to the selected object and obtain the object’s Left and Top properties:

JavaScript, JScript

// This routine is called when the OnObjectPicked event occurs
function UserForm1_ObjectPicker2_OnObjectPicked(Sender)
{
  var obj, objName, leftProperty, topProperty;

  // Obtain the name of the selected object
  objName = UserForms.UserForm1.ObjectPicker2.PickedObjectName;

  // Get the object reference
  obj = eval(objName);

  // Obtain the object properties
  leftProperty = obj.Left;
  topProperty = obj.Top;
  Log.Message("Left: " + leftProperty);
  Log.Message("Top: " + topProperty);
}

Python

# This routine is called when the OnObjectPicked event occurs
def UserForm1_ObjectPicker2_OnObjectPicked(Sender):
  # Obtain the name of the selected object
  objName = UserForms.UserForm1.ObjectPicker2.PickedObjectName

  # Get the object reference
  obj = eval(objName)

  # Obtain the object properties
  leftProperty = obj.Left
  topProperty = obj.Top
  Log.Message("Left: " + str(leftProperty))
  Log.Message("Top: " + str(topProperty))

VBScript

' This routine is called when the OnObjectPicked event occurs
Sub UserForm1_ObjectPicker2_OnObjectPicked(Sender)
  Dim obj, objName, leftProperty, topProperty

  ' Obtain the name of the selected object
  objName = UserForms.UserForm1.ObjectPicker2.PickedObjectName

  ' Get the object reference
  Set obj = Eval(objName)

  ' Obtain the object properties
  leftProperty = obj.Left
  topProperty = obj.Top
  Log.Message "Left: " & leftProperty
  Log.Message "Top: " & topProperty
End Sub

DelphiScript

// This routine is called when the OnObjectPicked event occurs
procedure UserForm1_ObjectPicker2_OnObjectPicked(Sender);
var
  obj, objName, leftProperty, topProperty : OleVariant;
begin
  // Obtain the name of the selected object
  objName := UserForms.UserForm1.ObjectPicker2.PickedObjectName;

  // Get the object reference
  obj := Evaluate(objName);

  // Obtain the object properties
  leftProperty := obj.Left;
  topProperty := obj.Top;
  Log.Message('Left: ' + aqConvert.VarToStr(leftProperty));
  Log.Message('Top: ' + aqConvert.VarToStr(topProperty));
end;

C++Script, C#Script

// This routine is called when the OnObjectPicked event occurs
function UserForm1_ObjectPicker2_OnObjectPicked(Sender)
{
  var obj, objName, leftProperty, topProperty;

  // Obtain the name of the selected object
  objName = UserForms["UserForm1"]["ObjectPicker2"]["PickedObjectName"];

  // Get the object reference
  obj = eval(objName);

  // Obtain the object properties
  leftProperty = obj["Left"];
  topProperty = obj["Top"];
  Log["Message"]("Left: " + leftProperty);
  Log["Message"]("Top: " + topProperty);
}

 

TObjectPicker Properties

TObjectPicker Methods

TObjectPicker Events

See Also

User Forms
Script Extensions

Highlight search results