NewArray Method

Applies to TestComplete 14.10, last modified on June 5, 2019

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 Classes.NewArray method creates a new ArrayObject object. Use this object to create array properties in classes. If you create objects on the basis of a class, all objects' arrays will have the same items that the “class” array has.

Declaration

ClassesObj.NewArray()

ClassesObj An expression, variable or parameter that specifies a reference to a Classes object
Result An ArrayObject object

Applies To

The method is applied to the following object:

Result Value

An ArrayObject object.

Example

The code below creates a new array, adds some properties to it and then posts the total number of array items to the test log.

JavaScript, JScript

function NewArrayExample()
{
  // Creates a new array
  var NewArray = ODT.Classes.NewArray();
  // Adds properties to the new array
  NewArray.AddItem(123);
  NewArray.AddItem("My text!");
  NewArray.AddItem(false);
  
  // Obtains the total number of array items
  var ItemsNum = NewArray.Count;
  Log.Message("Array contains " + ItemsNum + " items");
}

VBScript

Sub NewArrayExample()

  ' Creates a new array
  Set NewArray = ODT.Classes.NewArray()
  ' Adds properties to the new array
  NewArray.AddItem(123)
  NewArray.AddItem("My text!")
  NewArray.AddItem(false)
  
  ' Obtains the total number of array items
  ItemsNum = NewArray.Count
  Log.Message("Array contains " & ItemsNum & " items")

End Sub

DelphiScript

function NewArrayExample;
var NewArray, ItemsNum;
begin

  // Creates a new array
  NewArray := ODT.Classes.NewArray();
  // Adds properties to the new array
  NewArray.AddItem(123);
  NewArray.AddItem('My text!');
  NewArray.AddItem(false);
  
  // Obtains the total number of array items
  ItemsNum := NewArray.Count;
  Log.Message('Array contains ' + IntToStr(ItemsNum) + ' items');

end;

C++Script, C#Script

function NewArrayExample()
{
  // Creates a new array
  var NewArray = ODT["Classes"]["NewArray"]();
  // Adds properties to the new array
  NewArray["AddItem"](123);
  NewArray["AddItem"]("My text!");
  NewArray["AddItem"](false);
  
  // Obtains the total number of array items
  var ItemsNum = NewArray["Count"];
  Log["Message"]("Array contains " + ItemsNum + " items");
}

See Also

ArrayObject Object

Highlight search results