ScriptProc Property

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 MethodDeclaration.ScriptProc property specifies the scripting routine that is used as a method of an ODT class. The routine must be specified in the unit_name.routine_name format. Both unit_name and routine_name are required. The unit_name 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).

If you assign an empty string to ScriptProc, you will have to specify the ScriptProc property of the corresponding method 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 operations.

Declaration

MethodDeclarationObj.ScriptProc

Read-Write Property String
MethodDeclarationObj An expression, variable or parameter that specifies a reference to a MethodDeclaration object

Applies To

The property is applied to the following object:

Property Value

A string that specifies the scripting routine for the method.

Remarks

If you modify the ScriptProc property, it will also be modified in methods in all the objects that are based on this class on conditions that you did not modify the ScriptProc property of the “object” method after the object was created.

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"]();
  ...
}

Example

The following code snippet obtains the MethodDeclaration object and specifies the script routine the obtained method will execute.

JavaScript, JScript

function MethodDeclarationSample()
{
  var ClassObj, MethodDecl;
  // Obtains the ODT class by its name
  ClassObj = ODT.Classes.Items("NewClass");
  // Obtains the method declaration by the method’s index
  MethodDecl = ClassObj.Methods(0);
  // Specifies the script routine the method will execute
  MethodDecl.ScriptProc = "Unit1.Test1";

  …

}

VBScript

Sub MethodDeclarationSample

  ' Obtains the ODT class by its name
  Set ClassObj = ODT.Classes.Items("NewClass")
  ' Obtains the method declaration by the method’s index
  Set MethodDecl = ClassObj.Methods(0)
  ' Specifies the script routine the method will execute
  MethodDecl.ScriptProc = "Unit1.Test1"

  …

End Sub

DelphiScript

procedure MethodDeclarationSample();
var ClassObj, MethodDecl;
begin
  // Obtains the ODT class by its name
  ClassObj := ODT.Classes.Items['NewClass'];
  // Obtains the method declaration by the method’s index
  MethodDecl := ClassObj.Methods[0];
  // Specifies the script routine the method will execute
  MethodDecl.ScriptProc := 'Unit1.Test1';

  …

end;

C++Script, C#Script

function MethodDeclarationSample()
{
  var ClassObj, MethodDecl;
  // Obtains the ODT class by its name
  ClassObj = ODT["Classes"]["Items"]("NewClass");
  // Obtains the method declaration by the method’s index
  MethodDecl = ClassObj["Methods"](0);
  // Specifies the script routine the method will execute
  MethodDecl["ScriptProc"] = "Unit1.Test1";

  …

}

See Also

Class Object
ScriptProc Property
Name Property

Highlight search results