Methods Property

Applies to TestComplete 15.64, last modified on May 16, 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 Class.Methods property returns the MethodDeclaration object that represents a class method. The total number of methods is specified by the MethodCount property.

Declaration

ClassObj.Methods(Index)

Read-Only Property A MethodDeclaration object
ClassObj An expression, variable or parameter that specifies a reference to a Class object
Index [in]    Required    Variant    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

Index

The Index parameter specifies either a method name, or index. The first method has index 0, the second - 1, and so on.

Property Value

A MethodDeclaration object.

Remarks

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

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

Example

The code below posts the names of all the methods that belong to the MyClass class to the test log.

JavaScript, JScript

function MethodsExample()
{
  // Specifies the class name
  var MyClass = ODT.Classes.MyClass;
  // Obtains the total number of the class's methods
  var MethNum = MyClass.MethodCount;
  
  // Iterates through the methods
  for (var i = 0; i < MethNum; i++)
  {
    var MethName = MyClass.Methods(i).Name;
    // Posts a method's name to the test log
    Log.Message(MethName);
  }
}

VBScript

Sub MethodsExample()

  ' Specifies the class name
  Set MyClass = ODT.Classes.MyClass
  ' Obtains the total number of the class's methods
  MethNum = MyClass.MethodCount
  
  ' Iterates through the methods
  For i = 0 to (MethNum - 1)
    MethName = MyClass.Methods(i).Name
    ' Posts a method's name to the test log
    Log.Message(MethName)
  Next

End Sub

DelphiScript

function MethodsExample;
var MyClass, MethNum, i, MethName;
begin

  // Specifies the class name
  MyClass := ODT.Classes.MyClass;
  // Obtains the total number of the class's methods
  MethNum := MyClass.MethodCount;
  
  // Iterates through the methods
  for i := 0 to (MethNum - 1) do
  begin
    MethName := MyClass.Methods[i].Name;
    // Posts a method's name to the test log
    Log.Message(MethName);
  end;

end;

C++Script, C#Script

function MethodsExample()
{
  // Specifies the class name
  var MyClass = ODT["Classes"]["MyClass"];
  // Obtains the total number of the class's methods
  var MethNum = MyClass["MethodCount"];
  
  // Iterates through the methods
  for (var i = 0; i < MethNum; i++)
  {
    var MethName = MyClass["Methods"](i)["Name"];
    // Posts a method's name to the test log
    Log["Message"](MethName);
  }
}

See Also

MethodDeclaration Object
Methods Property
MethodCount Property
Properties Property

Highlight search results