AddProperty Method

Applies to TestComplete 14.71, 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 Class.AddProperty method adds a new property to the class and returns this property as the PropertyDeclaration object. Note that when you add a property to the class, this property is also added to all the objects that are based on this class.

Declaration

ClassObj.AddProperty(NameValue)

ClassObj An expression, variable or parameter that specifies a reference to a Class object
Name [in]    Required    String    
Value [in]    Optional    Variant    
Result A PropertyDeclaration object

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

Name

Specifies the name of the new property. This 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).

Value

Specifies the property value: string, integer, date, etc. Value can be of any type, except OLE object, (see the Remarks section for details). Value is used as a default property value. Later, it can be changed in objects that are based on the class.

Result Value

The new property represented as a PropertyDeclaration object.

Remarks

To add an array property, use the AddPropOfArrayType method. To add a property of an ODT class type, use the AddPropOfClassType method.

Default property values of ODT classes cannot be objects, except those objects which are ODT arrays and classes. Other objects, for example process or window objects, cannot be default class property values. You can only assign object values to properties of class instances, that is Object objects created at run-time using the Classes.New method.

The following code illustrates this restriction:

JavaScript, JScript

var w = Sys.Process("App").Window("WndClass", "WndCaption");

var oClass = ODT.Classes.Declare("NewClass"); // Declaring a new class
oClass.AddProperty("NewProperty", w);         // Incorrect!!! oClass is a class declaration

var oObj = ODT.Classes.New("NewClass"); // Creating a class instance
oObj.AddProperty("NewProperty", w);     // Correct: oObj is a class instance

VBScript

Set w = Sys.Process("App").Window("WndClass", "WndCaption")

Set oClass = ODT.Classes.Declare("NewClass") ' Declaring a new class
oClass.AddProperty "NewProperty", w         ' Incorrect!!! oClass is a class declaration

Set oObj = ODT.Classes.New("NewClass") ' Creating a class instance
oObj.AddProperty "NewProperty", w     ' Correct: oObj is a class instance

DelphiScript

var
  w, oClass, oObj: OleVariant;
...
w := Sys.Process('App').Window('WndClass', 'WndCaption');

oClass := ODT.Classes.Declare('NewClass'); // Declaring a new class
oClass.AddProperty('NewProperty', w);      // Incorrect!!! oClass is a class declaration

oObj := ODT.Classes.New('NewClass'); // Creating a class instance
oObj.AddProperty('NewProperty', w);  // Correct: oObj is a class instance

C++Script, C#Script

var w = Sys["Process"]("App")["Window"]("WndClass", "WndCaption");

var oClass = ODT["Classes"]["Declare"]("NewClass"); // Declaring a new class
oClass["AddProperty"]("NewProperty", w);            // Incorrect!!! oClass is a class declaration

var oObj = ODT["Classes"]["New"]("NewClass"); // Creating a class instance
oObj["AddProperty"]("NewProperty", w);        // Correct: oObj is a class instance

See Also

PropertyDeclaration Object
AddProperty Method
AddPropOfArrayType Method
AddPropOfClassType Method
DeleteProperty Method
AddMethod Method

Highlight search results