AddItemOfClassType Method

Applies to TestComplete 15.63, last modified on April 23, 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 specified class. The AddItemOfClassType method creates this object and returns a reference to it. If there is no class with the specified name, an error occurs.

Declaration

ArrayObjectObj.AddItemOfClassType(ClassName)

ArrayObjectObj An expression, variable or parameter that specifies a reference to an ArrayObject object
ClassName [in]    Required    String    
Result An ArrayObject 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 ArrayObject object.

Example

The code below creates two classes, MyClass and TestClass, and adds the Exists property of the array type to the TestClass class. Then the routine adds three items to the Exists property. The first of these items is the item of the MyClass type.

JavaScript, JScript

function AddIPropOfClassType()
{
   // Creates a new class
   ODT.Classes.Declare("MyClass");
   var Obj = ODT.Classes.New("MyClass");
   // Adds two properties to the class
   Obj.AddProperty("Property1", 123);
   Obj.AddProperty("Property2", 456);
   // Creates one more class
   var ObjNew = ODT.Classes.New("TestClass");
   // Adds the Exists property of the array type
   // to the TestClass class
   var Prop = ObjNew.AddPropOfArrayType("Exists");
   // Adds three items to the Exists property
   Prop.AddItemOfClassType("MyClass");
   Prop.AddItem(123);
   Prop.AddItem("MyString");
}

VBScript

Sub AddIPropOfClassType
   ' Creates a new class
   ODT.Classes.Declare("MyClass")
   Set Obj = ODT.Classes.New("MyClass")
   ' Adds two properties to the class
   Call Obj.AddProperty("Property1", 123)
   Call Obj.AddProperty("Property2", 456)
   ' Creates one more class
   Set ObjNew = ODT.Classes.New("TestClass")
   ' Adds the Exists property of the array type
   ' to the TestClass class
   Set Prop = ObjNew.AddPropOfArrayType("Exists")
   ' Adds three items to the Exists property
   Prop.AddItemOfClassType("MyClass")
   Prop.AddItem(123)
   Prop.AddItem("MyString")
End Sub

DelphiScript

function AddIPropOfClassType;
var Obj, ObjNew, Prop;
begin
   // Creates a new class
   ODT.Classes.Declare('MyClass');
   Obj := ODT.Classes.New('MyClass');
   // Adds two properties to the class
   Obj.AddProperty('Property1', 123);
   Obj.AddProperty('Property2', 456);
   // Creates one more class
   ObjNew := ODT.Classes.New('TestClass');
   // Adds the Exists property of the array type
   // to the TestClass class
   Prop := ObjNew.AddPropOfArrayType('Exists');
   // Adds three items to the Exists property
   Prop.AddItemOfClassType('MyClass');
   Prop.AddItem(123);
   Prop.AddItem('MyString');
end;

C++Script, C#Script

function AddIPropOfClassType()
{
   // Creates a new class
   ODT["Classes"]["Declare"]("MyClass");
   var Obj = ODT["Classes"]["New"]("MyClass");
   // Adds two properties to the class
   Obj["AddProperty"]("Property1", 123);
   Obj["AddProperty"]("Property2", 456);
   // Creates one more class
   var ObjNew = ODT["Classes"]["New"]("TestClass");
   // Adds the Exists property of the array type
   // to the TestClass class
   var Prop = ObjNew["AddPropOfArrayType"]("Exists");
   // Adds three items to the Exists property
   Prop["AddItemOfClassType"]("MyClass");
   Prop["AddItem"](123);
   Prop["AddItem"]("MyString");
}

See Also

AddItem Method
AddItemOfArrayType Method
DeleteItem Method
AddItemOfClassType Method

Highlight search results