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.AddPropOfClassType
method adds a new object property to the object and returns this property as the Object
object. The new property will hold a reference to the object that is based on the class specified by the ClassName parameter.
Declaration
ObjectObj.AddPropOfClassType(PropertyName, ClassName)
ObjectObj | An expression, variable or parameter that specifies a reference to an Object object | |||
PropertyName | [in] | Required | String | |
ClassName | [in] | Required | String | |
Result | An Object 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 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).
ClassName
Specifies the name of the class on which the object, whose reference is held in the new property, will be based. If there is no class with the specified name, it will be created.
Result Value
The new property represented as an Object
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 two new classes, creates an object that contains an instance of the first created class and then adds a class type property to the object. The property represents an object of the second created class type.
JavaScript, JScript
{
var NewClass, TestClass, MyObject, TestObject;
// Declares a new class
NewClass = ODT.Classes.Declare("NewClass");
// Adds methods and properties to the new class
…
// Declares another class
TestClass = ODT.Classes.Declare("TestClass");
// Adds methods and properties to the class
…
// Creates an object
MyObject = ODT.Classes.New("NewClass");
// Adds a new class type property to the object
TestObject = MyObject.AddPropOfClassType("ClassTypeProperty","TestClass");
…
}
VBScript
' Declares a new class
Set NewClass = ODT.Classes.Declare("NewClass")
' Adds methods and properties to the new class
…
' Declares another class
Set TestClass = ODT.Classes.Declare("TestClass")
' Adds methods and properties to the class
…
' Creates an object
Set MyObject = ODT.Classes.New("NewClass")
' Adds a new class type property to the object
Set TestObject = MyObject.AddPropOfClassType("ClassTypeProperty","TestClass")
…
End Sub
DelphiScript
var NewClass, TestClass, MyObject, TestObject;
begin
// Declares a new class
NewClass := ODT.Classes.Declare('NewClass');
// Adds methods and properties to the new class
…
// Declares another class
TestClass := ODT.Classes.Declare('TestClass');
// Adds methods and properties to the class
…
// Creates an object
MyObject := ODT.Classes.New('NewClass');
// Adds a new class type property to the object
TestObject := MyObject.AddPropOfClassType('ClassTypeProperty','TestClass');
…
end;
C++Script, C#Script
{
var NewClass, TestClass, MyObject, TestObject;
// Declares a new class
NewClass = ODT["Classes"]["Declare"]("NewClass");
// Adds methods and properties to the new class
…
// Declares another class
TestClass = ODT["Classes"]["Declare"]("TestClass");
// Adds methods and properties to the class
…
// Creates an object
MyObject = ODT["Classes"]["New"]("NewClass");
// Adds a new class type property to the object
TestObject = MyObject["AddPropOfClassType"]("ClassTypeProperty","TestClass");
…
}
See Also
AddProperty Method
AddPropOfArrayType Method
DeleteProperty Method
Properties Property
AddPropOfClassType Method