DeleteMethod Method

Applies to TestComplete 15.47, last modified on January 20, 2023

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

Deletes a method from the ClassObj class. Note that when you delete a method from a class, the method is deleted from all the objects that are based on this class.

Declaration

ClassObj.DeleteMethod(Name)

ClassObj An expression, variable or parameter that specifies a reference to a Class object
Name [in]    Required    String    
Result None

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Name

Specifies the name of the method to be deleted. If the class does not contain the method with the specified name, an error occurs.

Result Value

None.

Example

The code below deletes all the methods that belong to the MyClass class and whose names contain the "abracadabra" substring from a project.

JavaScript, JScript

function DeleteMethodExample()
{
  // 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 MethodItem = MyClass.Methods(i);
    // Obtains the name of the current method
    var Name = MethodItem.Name;
    // Checks whether the method's name contains the
    // "abracadabra" substring
    var Res = aqString.Find(Name, "abracadabra");
    if (Res != -1)
    {
      // Deletes the method and updates the counters
      MyClass.DeleteMethod(Name);
      i--;
      MethNum--;
    }
  }
  
}

VBScript

Sub DeleteMethodExample()

  ' 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)
  
    Set MethodItem = MyClass.Methods(i)
    ' Obtains the name of the current method
    Name = MethodItem.Name
    ' Checks whether the method's name contains the
    ' "abracadabra" substring
    Res = aqString.Find(Name, "abracadabra")
    If Not (Res = -1) Then
      ' Deletes the method and updates the counters
      MyClass.DeleteMethod(Name)
      i = i - 1
      MethNum = MethNum - 1
    End If
  Next
  
End Sub

DelphiScript

function DeleteMethodExample;
var MyClass, MethNum, i, MethodItem, Name, Res;
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
    MethodItem := MyClass.Methods[i];
    // Obtains the name of the current method
    Name := MethodItem.Name;
    // Checks whether the method's name contains the
    // "abracadabra" substring
    Res := aqString.Find(Name, 'abracadabra');
    if not (Res = -1) then
    begin
      // Deletes the method and updates the counters
      MyClass.DeleteMethod(Name);
      Dec(i);
      Dec(MethNum);
    end;
  end;
  
end;

C++Script, C#Script

function DeleteMethodExample()
{
  // 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 MethodItem = MyClass["Methods"](i);
    // Obtains the name of the current method
    var Name = MethodItem["Name"];
    // Checks whether the method's name contains the
    // "abracadabra" substring
    var Res = aqString["Find"]( Name, "abracadabra" );
    if (Res != -1)
    {
      // Deletes the method and updates the counters
      MyClass["DeleteMethod"]( Name );
      i--;
      MethNum--;
    }
  }
  
}

See Also

AddMethod Method
DeleteProperty Method
Methods Property
MethodDeclaration Object
DeleteMethod Method

Highlight search results