AddPropOfClassType Method

Applies to TestComplete 15.68, last modified on October 16, 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 Class.AddPropOfClassType method adds a new “class” property to the class and returns this property as the Class object. The new property will hold a reference to an object that is based on the class specified by the ClassName parameter. If there is no class with the specified name, it will be created.

Declaration

ClassObj.AddPropOfClassType(PropertyName, ClassName)

ClassObj An expression, variable or parameter that specifies a reference to a Class object
PropertyName [in]    Required    String    
ClassName [in]    Required    String    
Result A Class object

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

PropertyName

The PropertyName parameter specifies the name of the new property. The property name must be unique within the class. If the class 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).

ClassName

Specifies the name of the class on which the object, whose reference is held in the new property, will be based.

Result Value

The new property represented as a Class object.

Remarks

When you add a new property to the class, it is also added to all the objects that are based on this class.

Example

The code below declares the MyClass class, adds some properties to it and then declares a new class and adds a property of the MyClass type to this class.

JavaScript, JScript

function AddPropOfClassTypeExample()
{
  // Declares the MyClass class
  ODT.Classes.Declare("MyClass");
  // Obtains the declared class
  var MyClass = ODT.Classes.MyClass;
  // Adds a new property to the class
  MyClass.AddProperty("Property1", 123);
  
  // ...
  
  // Declares the MyNewClass class and obtains it
  ODT.Classes.Declare("MyNewClass");
  var NewClass = ODT.Classes.MyNewClass;
  NewClass.AddProperty("Property2_1", 456);
  // Adds a property of the MyClass type to the MyNewClass class
  NewClass.AddPropOfClassType("Property2_2", "MyClass");
  
}

VBScript

Sub AddPropOfClassTypeExample()

  ' Declares the MyClass class
  ODT.Classes.Declare("MyClass")
  ' Obtains the declared class
  Set MyClass = ODT.Classes.MyClass
  ' Adds a new property to the class
  Call MyClass.AddProperty("Property1", 123)
  
  ' ...
  
  ' Declares the MyNewClass class and obtains it
  ODT.Classes.Declare("MyNewClass")
  Set NewClass = ODT.Classes.MyNewClass
  Call NewClass.AddProperty("Property2_1", 456)
  ' Adds a property of the MyClass type to the MyNewClass class
  Call NewClass.AddPropOfClassType("Property2_2", "MyClass")
  
End Sub

DelphiScript

function AddPropOfClassTypeExample;
var MyClass, NewClass;
begin

  // Declares the MyClass class
  ODT.Classes.Declare('MyClass');
  // Obtains the declared class
  MyClass := ODT.Classes.MyClass;
  // Adds a new property to the class
  MyClass.AddProperty('Property1', 123);
  
  // ...
  
  // Declares the MyNewClass class and obtains it
  ODT.Classes.Declare('MyNewClass');
  NewClass := ODT.Classes.MyNewClass;
  NewClass.AddProperty('Property2_1', 456);
  // Adds a property of the MyClass type to the MyNewClass class
  NewClass.AddPropOfClassType('Property2_2', 'MyClass');
  
end;

C++Script, C#Script

function AddPropOfClassTypeExample()
{
  // Declares the MyClass class
  ODT.Classes["Declare"]("MyClass");
  // Obtains the declared class
  var MyClass = ODT["Classes"]["MyClass"];
  // Adds a new property to the class
  MyClass["AddProperty"]("Property1", 123);
  
  // ...
  
  // Declares the MyNewClass class and obtains it
  ODT["Classes"]["Declare"]("MyNewClass");
  var NewClass = ODT["Classes"]["MyNewClass"];
  NewClass["AddProperty"]("Property2_1", 456);
  // Adds a property of the MyClass type to the MyNewClass class
  NewClass["AddPropOfClassType"]("Property2_2", "MyClass");
  
}

See Also

AddProperty Method
AddPropOfArrayType Method
DeleteProperty Method
Properties Property
AddPropOfClassType Method

Highlight search results