AddItem Method

Applies to TestComplete 15.69, last modified on November 13, 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 ArrayType.AddItem method adds a new item with the specified Value to the end of the array and returns the ArrayItem object that provides a scripting interface to the new item. When you add an item to the array in a class, a new item is added or inserted into the appropriate position of arrays in all the objects that are based on this class.

Declaration

ArrayTypeObj.AddItem(Value)

ArrayTypeObj An expression, variable or parameter that specifies a reference to an ArrayType object
Value [in]    Optional    Variant    
Result An ArrayItem object

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Value

Specifies the value of the new array item. This parameter can hold any Variant-compatible value: string, integer, date, object or it can be an array itself.

Result Value

The new array item represented as an ArrayItem object.

Example

The code below adds a new MyProperty property of the array type to the specified class and then adds three new items to the created property.

JavaScript, JScript

function ArrayTypeExample()
{
    // Creates a new class
    var Obj = ODT.Classes.Declare("MyClass");
    // Adds a new property of the array type to the class
    var Prop = Obj.AddPropOfArrayType("MyProperty");
    // Adds three items to the MyProperty property
    Prop.AddItem(159);
    Prop.AddItem("Hello, world.");
    var ArrItem = Prop.AddItemOfArrayType;
    // ...
}

VBScript

Sub ArrayTypeExample
    ' Creates a new class
    Set Obj = ODT.Classes.Declare("MyClass")
    ' Adds a new property of the array type to the class
    Set Prop = Obj.AddPropOfArrayType("MyProperty")
    ' Adds three items to the MyProperty property
    Prop.AddItem(159)
    Prop.AddItem("Hello, world.")
    Set ArrItem = Prop.AddItemOfArrayType
    ' ...
End Sub

DelphiScript

function ArrayTypeExample;
var Obj, Prop, ArrItem;
begin
    // Creates a new class
    Obj := ODT.Classes.Declare('MyClass');
    // Adds a new property of the array type to the class
    Prop := Obj.AddPropOfArrayType('MyProperty');
    // Adds three items to the MyProperty property
    Prop.AddItem(159);
    Prop.AddItem('Hello, world.');
    ArrItem := Prop.AddItemOfArrayType;
    // ...
end;

C++Script, C#Script

function ArrayTypeExample()
{
    // Creates a new class
    var Obj = ODT["Classes"]["Declare"]("MyClass");
    // Adds a new property of the array type to the class
    var Prop = Obj["AddPropOfArrayType"]("MyProperty");
    // Adds three items to the MyProperty property
    Prop["AddItem"](159);
    Prop["AddItem"]("Hello, world.");
    var ArrItem = Prop["AddItemOfArrayType"];
    // ...
}

See Also

Items Property
AddItemOfArrayType Method
AddItemOfClassType Method
DeleteItem Method
AddItem Method

Highlight search results