AddItemOfClassType 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

Adds a new item to the end of the array. The new item will hold a reference to an object, which is based on the class whose name is specified by the ClassName parameter. Note that when you add an item to the array in a class, a new item will be added to or inserted into the appropriate position in arrays in all the objects that are based on this class.

Declaration

ArrayTypeObj.AddItemOfClassType(ClassName)

ArrayTypeObj An expression, variable or parameter that specifies a reference to an ArrayType object
ClassName [in]    Required    String    
Result A Class object

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

ClassName

Specifies the name of the class on which the new array item is based.

Result Value

The new item represented as an Class object.

Example

The code below declares two new classes, adds a property of the array type to the first class and then adds an item of the second class's type to the created property.

JavaScript, JScript

function AddItemExample()
{
    // Creates two new classes
    var Obj = ODT.Classes.Declare("MyClass");
    ODT.Classes.Declare("TestClass");
    // Adds a new property of the array type to the first class
    var Prop = Obj.AddPropOfArrayType("MyProperty");
    // Adds three items to the MyProperty property
    Prop.AddItemOfClassType("TestClass");
    Prop.AddItem(123);
    Prop.AddItem("Hello, world.");
    // ...
}

VBScript

Sub AddItemExample
    ' Creates two new classes
    Set Obj = ODT.Classes.Declare("MyClass")
    ODT.Classes.Declare("TestClass")
    ' Adds a new property of the array type to the first class
    Set Prop = Obj.AddPropOfArrayType("MyProperty")
    ' Adds three items to the MyProperty property
    Prop.AddItemOfClassType("TestClass")
    Prop.AddItem(123)
    Prop.AddItem("Hello, world.")
    ' ...
End Sub

DelphiScript

function AddItemExample;
var Obj, Prop;
begin
    // Creates two new classes
    Obj := ODT.Classes.Declare('MyClass');
    ODT.Classes.Declare('TestClass');
    // Adds a new property of the array type to the first class
    Prop := Obj.AddPropOfArrayType('MyProperty');
    // Adds three items to the MyProperty property
    Prop.AddItemOfClassType('TestClass');
    Prop.AddItem(123);
    Prop.AddItem('Hello, world.');
    // ...
end;

C++Script, C#Script

function AddItemExample()
{
    // Creates two new classes
    var Obj = ODT["Classes"]["Declare"]("MyClass");
    ODT["Classes"]["Declare"]("TestClass");
    // Adds a new property of the array type to the first class
    var Prop = Obj["AddPropOfArrayType"]("MyProperty");
    // Adds three items to the MyProperty property
    Prop["AddItemOfClassType"]("TestClass");
    Prop["AddItem"](123);
    Prop["AddItem"]("Hello, world.");
    // ...
}

See Also

Items Property
AddItem Method
AddItemOfArrayType Method
DeleteItem Method
AddItemOfClassType Method

Highlight search results