Items Property

Applies to TestComplete 14.70, last modified on April 22, 2021

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 ArrayObject.Items property returns the ArrayItem object that provides access to the array item specified by its index. The total number of elements in the array is specified by the Count property.

Note that the Items property is the default one and you can omit it in your scripts. Therefore, the following two lines are equivalent:

ArrayObj.Items(1)
ArrayObj(1)

Declaration

ArrayObjectObj.Items(Index)

Read-Only Property An ArrayItem object
ArrayObjectObj An expression, variable or parameter that specifies a reference to an ArrayObject object
Index [in]    Required    Integer    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

Index

Specifies the index of the desired item in the array.

Property Value

The ArrayItem object that provides access to the specified array item.

Remarks

To specify the item value, use the ArrayItem.Value property. An array item can store any Variant-compatible value: string, integer, date, object, array, etc. The Value property is used by default in the ArrayItem object and you can omit it. Therefore, you can specify the item value in any of the following ways:

ArrayObj.Items(1).Value = 10
ArrayObj.Items(1) = 10
ArrayObj(1) = 10 // since both Value and Items are default properties
Note: If you use DelphiScript, you need to enclose Index in square brackets: Items[Index].

Example

The code below obtains a collection of items that belong to the MyProperty property of the array type and then posts the items' values to the test log.

JavaScript, JScript

function ArrayItems()
{
   // Specifies the property to obtain information about
   var Prop = ODT.Classes.TestClass.MyProperty;
   // Obtains the total number of items that belong to the MyProperty array
   var iNum = Prop.Count;
   for (var i = 0; i < iNum; i++)
   {
     // Obtains the current item's value
     var iVal = Prop.Items(i).Value;
     Log.Message("The " + i + " item's value is: " + iVal);
   }
}

VBScript

Sub ArrayItems
   ' Specifies the property to obtain information about
   Set Prop = ODT.Classes.TestClass.MyProperty
   ' Obtains the total number of items that belong to the MyProperty array
   iNum = Prop.Count
   For i = 0 to iNum-1
     ' Obtains the current item's value
     iVal = Prop.Items(i).Value
     Log.Message("The " & i & " item's value is: " & iVal)
   Next
End Sub

DelphiScript

function ArrayItems;
var Prop, iNum, i, iVal;
begin
   // Specifies the property to obtain information about
   Prop := ODT.Classes.TestClass.MyProperty;
   // Obtains the total number of items that belong to the MyProperty array
   iNum := Prop.Count;
   for i := 0 to iNum-1 do
   begin
     // Obtains the current item's value
     iVal := Prop.Items(i).Value;
     Log.Message('The ' + i + ' item''s value is: ' + iVal);
   end;
end;

C++Script, C#Script

function ArrayItems()
{
   // Specifies the property to obtain information about
   var Prop = ODT["Classes"]["TestClass"]["MyProperty"];
   // Obtains the total number of items that belong to the MyProperty array
   var iNum = Prop["Count"];
   for (var i = 0; i < iNum; i++)
   {
     // Obtains the current item's value
     var iVal = Prop["Items"](i)["Value"];
     Log["Message"]("The " + i + " item's value is: " + iVal);
   }
}

See Also

Items Property
AddItem Method
AddItemOfArrayType Method
AddItemOfClassType Method
DeleteItem Method

Highlight search results