AddPropOfArrayType 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 Object.AddPropOfArrayType method adds a new array property to the object and returns this property as the ArrayObject object. You can use this object to add items to or delete them from the array.

Declaration

ObjectObj.AddPropOfArrayType(Name)

ObjectObj An expression, variable or parameter that specifies a reference to an Object object
Name [in]    Required    String    
Result An ArrayObject object

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Name

Specifies the name of the new property. The property name must be unique within the object. If the object already contains a method or property with the specified name, an error will occur. Since the property name is used to address the property in scripts, it must match the naming rules of the selected scripting language (it must be a valid identifier).

Result Value

The new property represented as an ArrayObject object.

Remarks

Note that a new method is added to the Object_Obj object only, it is not added to the class on which Object_Obj is based or to other objects that are based on this class.

Example

The following code snippet declares a new class, adds two properties to it and creates an object that contains an instance of the created class. After that, it adds an array type property to the object and populates the array with several items.

JavaScript, JScript

function ObjectSample()
{
  var NewClass, MyObject, ArrayProp, ArrayItem1, ArrayItem2, ArrayItem3;
  // Declares a new class
  NewClass = ODT.Classes.Declare("NewClass");
  // Adds properties to the new class
  NewClass.AddProperty("Property1", 10);
  NewClass.AddProperty("Property2", "TestString");

  // Creates an object
  MyObject = ODT.Classes.New("NewClass");
  // Adds a new array type property to the object
  ArrayProp = MyObject.AddPropOfArrayType("ArrayProp");
  // Adds several items to the array
  var ArrayItem1 = ArrayProp.AddItem("Value1");
  var ArrayItem2 = ArrayProp.AddItem("Value2");
  var ArrayItem3 = ArrayProp.AddItem("Value3");

}

VBScript

Sub ObjectSample

  ' Declares a new class
  Set NewClass = ODT.Classes.Declare("NewClass")
  ' Adds properties to the new class
  Call NewClass.AddProperty("Property1", 10)
  Call NewClass.AddProperty("Property2", "TestString")

  ' Creates an object
  Set MyObject = ODT.Classes.New("NewClass")
  ' Adds a new array type property to the object
  Set ArrayProp = MyObject.AddPropOfArrayType("ArrayProp")
  ' Adds several items to the array
  Set ArrayItem1 = ArrayProp.AddItem("Value1")
  Set ArrayItem2 = ArrayProp.AddItem("Value2")
  Set ArrayItem3 = ArrayProp.AddItem("Value3")

End Sub

DelphiScript

procedure ObjectSample();
var NewClass, MyObject, ArrayProp, ArrayItem1, ArrayItem2, ArrayItem3;
begin
  // Declares a new class
  NewClass := ODT.Classes.Declare('NewClass');
  // Adds properties to the new class
  NewClass.AddProperty('Property1', 10);
  NewClass.AddProperty('Property2', 'TestString');

  // Creates an object
  MyObject := ODT.Classes.New('NewClass');
  // Adds a new array type property to the object
  ArrayProp := MyObject.AddPropOfArrayType('ArrayProp');
  // Adds several items to the array
  ArrayItem1 := ArrayProp.AddItem('Value1');
  ArrayItem2 := ArrayProp.AddItem('Value2');
  ArrayItem3 := ArrayProp.AddItem('Value3');

end;

C++Script, C#Script

function ObjectSample()
{
  var NewClass, MyObject, ArrayProp;
  // Declares a new class
  NewClass = ODT["Classes"]["Declare"]("NewClass");
  // Adds properties to the new class
  NewClass["AddProperty"]("Property1", 10);
  NewClass["AddProperty"]("Property2", "TestString");

  // Creates an object
  MyObject = ODT["Classes"]["New"]("NewClass");
  // Adds a new array type property to the object
  ArrayProp = MyObject["AddPropOfArrayType"]("ArrayProp");
  // Adds several items to the array
  var ArrayItem1 = ArrayProp["AddItem"]("Value1");
  var ArrayItem2 = ArrayProp["AddItem"]("Value2");
  var ArrayItem3 = ArrayProp["AddItem"]("Value3");

}

See Also

AddProperty Method
AddPropOfClassType Method
DeleteProperty Method
Properties Property
AddPropOfArrayType Method

Highlight search results