AddMethod Method

Applies to TestComplete 14.0, last modified on January 23, 2019

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.AddMethod method creates a new method in the class and returns this method as the MethodDeclaration object. Note that when you add a method to the class, the method is also added to all the objects that are based on this class.

Declaration

ClassObj.AddMethod(MethodNameScriptProc)

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

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

MethodName

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

ScriptProc

Specifies a script routine that will be used as the method. ScriptProc must be specified in the format unit_name.routine_name. Both unit_name and routine_name are required. The unit_name part specifies the unit where the routine is located. If this unit differs from the class unit, you should specify it in the USEUNIT (uses) clauses of the class unit (See Calling Routines and Variables Declared in Another Unit).

You can pass an empty string in the ScriptProc parameter. In this case, you will have to specify it in each object that is based on this class. This allows you to create objects containing methods that have the same name, but perform different actions.

Result Value

The new method represented as a MethodDeclaration object.

Remarks

To refer to the object instance that the given method belongs to in the routine code, use the keyword Self in DelphiScript or This in VBScript, JScript, C++Script or C#Script (note the first capital):

JavaScript, JScript

function Cls_Method ()
{
  ...
  This.Owner.Owner.Execute();
  ...
}

VBScript

Sub Cls_Method
  ...
  Call This.Owner.Owner.Execute
  ...
End Sub

DelphiScript

procedure Cls_Method;
begin
  ...
  Self.Owner.Owner.Execute;
  ...
end;

C++Script, C#Script

function Cls_Method ()
{
  ...
  This["Owner"]["Owner"]["Execute"]();
  ...
}

See Also

MethodDeclaration Object
AddMethod Method
AddProperty Method
DeleteMethod Method
Methods Property

Highlight search results