AddVarOfClassType Method

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

The object-driven testing (ODT) functionality is deprecated. Do not use it to create new tests. It will be removed from the product in one of the future releases. As an alternative, you can create custom classes in your scripts. For more information, see Alternatives to the ODT functionality.

Description

The Group.AddVarOfClassType method adds a new object variable to the group and returns it as an Object object.

Declaration

GroupObj.AddVarOfClassType(VariableName, ClassName)

GroupObj An expression, variable or parameter that specifies a reference to a Group object
VariableName [in]    Required    String    
ClassName [in]    Required    String    
Result An Object object

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

VariableName

Specifies the variable name. The variable name must be unique within the group. If the group contains another variable with the specified name, an error occurs.

ClassName

Specifies the name of the class on which the object, whose reference is held in the new variable, will be based.

Result Value

The new variable represented as an Object object.

Example

The code below declares a new MyClass class, adds some properties to it and then creates a new data group and adds a variable of the MyClass type to the created data group.

JavaScript, JScript

function AddVarOfClassType()
{
  // Declares a class and adds some properties to it
  var MyClass = ODT.Classes.Declare("MyClass");
  MyClass.AddProperty("Property_1", "Property_Value");
  var ArrayProp = MyClass.AddPropOfArrayType("Array_Property");
  ArrayProp.AddItem(123);
  ArrayProp.AddItem("My_Text");
  // ...
  // Creates a data group
  var Group = ODT.Data.AddGroup("MyGroup");
  // Adds a variable of the MyClass type to the MyGroup group
  Group.AddVarOfClassType("MyVariable", "MyClass");
}

VBScript

Sub AddVarOfClassType

  ' Declares a class and adds some properties to it
  Set MyClass = ODT.Classes.Declare("MyClass")
  Call MyClass.AddProperty("Property_1", "Property_Value")
  Set ArrayProp = MyClass.AddPropOfArrayType("Array_Property")
  ArrayProp.AddItem(123)
  ArrayProp.AddItem("My_Text")
  ' ...
  ' Creates a data group
  Set Group = ODT.Data.AddGroup("MyGroup")
  ' Adds a variable of the MyClass type to the MyGroup group
  Call Group.AddVarOfClassType("MyVariable", "MyClass")
     
End Sub

DelphiScript

function AddVarOfClassType;
var MyClass, ArrayProp, Group;
begin

  // Declares a class and adds some properties to it
  MyClass := ODT.Classes.Declare('MyClass');
  MyClass.AddProperty('Property_1', 'Property_Value');
  ArrayProp := MyClass.AddPropOfArrayType('Array_Property');
  ArrayProp.AddItem(123);
  ArrayProp.AddItem('My_Text');
  // ...
  // Creates a data group
  Group := ODT.Data.AddGroup('MyGroup');
  // Adds a variable of the MyClass type to the MyGroup group
  Group.AddVarOfClassType('MyVariable', 'MyClass');

end;

C++Script, C#Script

function AddVarOfClassType()
{
  // Declares a class and adds some properties to it
  var MyClass = ODT["Classes"]["Declare"]("MyClass");
  MyClass["AddProperty"]("Property_1", "Property_Value");
  var ArrayProp = MyClass["AddPropOfArrayType"]("Array_Property");
  ArrayProp["AddItem"](123);
  ArrayProp["AddItem"]("My_Text");
  // ...
  // Creates a data group
  var Group = ODT["Data"]["AddGroup"]("MyGroup");
  // Adds a variable of the MyClass type to the MyGroup group
  Group["AddVarOfClassType"]("MyVariable", "MyClass");
}

See Also

AddVariable Method
AddVarOfArrayType Method
DeleteVariable Method
Variables Property

Highlight search results