MethodCount Property

Applies to TestComplete 14.40, last modified on April 22, 2021

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

Use the Object.MethodCount property to get the total number of methods in the specified object.

Declaration

ObjectObj.MethodCount

Read-Only Property Integer
ObjectObj An expression, variable or parameter that specifies a reference to an Object object

Applies To

The property is applied to the following object:

Property Value

The total number of methods in the class.

Remarks

Note that this number will differ from the number of method in the class on which the object is based if you add methods to the object after it is created.

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

}

See Also

Methods Property
PropertyCount Property
MethodCount Property

Highlight search results