Methods Property

Applies to TestComplete 15.69, last modified on November 13, 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 Object.Methods property returns the Method object that represents the object's method. The total number of methods is specified by the MethodCount property.

Declaration

ObjectObj.Methods(Index)

Read-Only Property A Method object
ObjectObj An expression, variable or parameter that specifies a reference to an Object object
Index [in]    Required    Variant    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

Index

Specifies either the method name, or index. The first method has index 0, the second - 1, etc.

Property Value

A Method object.

Remarks

If the class or object does not contain a method with the specified name or index, an error occurs.

Example

The following code snippet declares a new class, adds several methods to it and creates an object based on the declared class. After that, it adds a new method to the object, iterates through the object’s methods and posts information on them to the test log.

JavaScript, JScript

function ObjectSample()
{
  var NewClass, MyObject, Method;
  // Declares a new class
  NewClass = ODT.Classes.Declare("NewClass");
  // Adds methods to the declared class
  NewClass.AddMethod("ClassMethod1", "Object_VB.Test1");
  NewClass.AddMethod("ClassMethod2", "Object_VB.Test2");

  // Creates an object based on the declared class
  MyObject = ODT.Classes.New("NewClass");
  // Adds a method to the object
  MyObject.AddMethod("ObjectMethod", "Object_VB.Test3");

  // Iterates through the object’s methods
  for (var i = 0; i < MyObject.MethodCount; i++)
  {
    // Obtains the object’s method
    Method = MyObject.Methods(i);

    // Posts information on the method to the test log
    Log.AppendFolder(Method.Name);
    Log.Message("Init method: " + Method.IsInit);
    Log.Message("Enabled: " + Method.Enabled);
    Log.Message("Script routine: " + Method.ScriptProc);
    Log.PopLogFolder();
  }

}

VBScript

Sub ObjectSample

  ' Declares a new class
  Set NewClass = ODT.Classes.Declare("NewClass")
  ' Adds methods to the declared class
  Call NewClass.AddMethod("ClassMethod1", "Object_VB.Test1")
  Call NewClass.AddMethod("ClassMethod2", "Object_VB.Test2")

  ' Creates an object based on the declared class
  Set MyObject = ODT.Classes.New("NewClass")
  ' Adds a method to the object
  Call MyObject.AddMethod("ObjectMethod", "Object_VB.Test3")

  ' Iterates through the object’s methods
  For i = 0 To MyObject.MethodCount - 1
    ' Obtains the object’s method
    Set Method = MyObject.Methods(i)

    ' Posts information on the method to the test log
    Log.AppendFolder Method.Name
    Log.Message "Init method: " & Method.IsInit
    Log.Message "Enabled: " & Method.Enabled
    Log.Message "Script routine: " & Method.ScriptProc
    Log.PopLogFolder
  Next

End Sub

DelphiScript

procedure ObjectSample();
var NewClass, MyObject, i, Method;
begin
  // Declares a new class
  NewClass := ODT.Classes.Declare('NewClass');
  // Adds methods to the declared class
  NewClass.AddMethod('ClassMethod1', 'Object_VB.Test1');
  NewClass.AddMethod('ClassMethod2', 'Object_VB.Test2');

  // Creates an object based on the declared class
  MyObject := ODT.Classes.New('NewClass');
  // Adds a method to the object
  MyObject.AddMethod('ObjectMethod', 'Object_VB.Test3');

  // Iterates through the object’s methods
  for i := 0 to MyObject.MethodCount - 1 do
  begin
    // Obtains the object’s method
    Method := MyObject.Methods[i];

    // Posts information on the method to the test log
    Log.AppendFolder(Method.Name);
    Log.Message('Init method: ' + aqConvert.VarToStr(Method.IsInit));
    Log.Message('Enabled: ' + aqConvert.VarToStr(Method.Enabled));
    Log.Message('Script routine: ' + Method.ScriptProc);
    Log.PopLogFolder();
  end;

end;

C++Script, C#Script

function ObjectSample()
{
  var NewClass, MyObject, Method;
  // Declares a new class
  NewClass = ODT["Classes"]["Declare"]("NewClass");
  // Adds methods to the declared class
  NewClass["AddMethod"]("ClassMethod1", "Object_VB.Test1");
  NewClass["AddMethod"]("ClassMethod2", "Object_VB.Test2");

  // Creates an object based on the declared class
  MyObject = ODT["Classes"]["New"]("NewClass");
  // Adds a method to the object
  MyObject["AddMethod"]("ObjectMethod", "Object_VB.Test3");

  // Iterates through the object’s methods
  for (var i = 0; i < MyObject["MethodCount"]; i++)
  {
    // Obtains the object’s method
    Method = MyObject["Methods"](i);

    // Posts information on the method to the test log
    Log["AppendFolder"](Method["Name"]);
    Log["Message"]("Init method: " + Method["IsInit"]);
    Log["Message"]("Enabled: " + Method["Enabled"]);
    Log["Message"]("Script routine: " + Method["ScriptProc"]);
    Log["PopLogFolder"]();
  }

}
Note: If you use DelphiScript, you should enclose the Index parameter in square brackets: Methods[Index].

See Also

Method Object
MethodCount Property
Properties Property

Highlight search results