DeleteMethod Method

Applies to TestComplete 15.70, last modified on December 17, 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

Use the Object.DeleteMethod method to delete a method from the Object object.

Declaration

ObjectObj.DeleteMethod(Name)

ObjectObj An expression, variable or parameter that specifies a reference to an Object 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 object does not contain a method with the specified name, an error will occur.

Result Value

None.

Remarks

Note that you cannot delete a method that was defined in a class. If you try to delete such a method, an error will occur. You can delete only those methods that were added to the object by the Object.AddMethod method. To delete a method that was declared in a class, use the Class.DeleteMethod method.

Example

The following code snippet declares a new class, creates an object based on this class and adds a method to the object. After the object’s methods are executed, the method added to the object is deleted.

JavaScript, JScript

function ObjectSample()
{

  var NewClass, MyObject, Method;
  // Declares a new class
  NewClass = ODT.Classes.Declare("NewClass");
  // Adds properties and methods to the new class
  NewClass.AddProperty("Property1", 10);
  NewClass.AddProperty("Property2", "Sample");
  NewClass.AddMethod("ClassMethod", "Unit1.Test1");

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

  // Iterates through the object’s methods and enables them
  for (var i = 0; i < MyObject.MethodCount; i++)
  {
    Method = MyObject.Methods(i);
    Method.Enabled = true;
  }

  // Processes the object’s properties and calls the object’s methods
  MyObject.Run();

  // Deletes the method added to the object
  MyObject.DeleteMethod("ObjectMethod");

}

VBScript

Sub ObjectSample

  ' Declares a new class
  Set NewClass = ODT.Classes.Declare("NewClass")
  ' Adds properties and methods to the new class
  Call NewClass.AddProperty("Property1", 10)
  Call NewClass.AddProperty("Property2", "Sample")
  Call NewClass.AddMethod("ClassMethod", "Unit1.Test1")

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

  ' Iterates through the object’s methods and enables them
  For i = 0 To MyObject.MethodCount - 1
    Set Method = MyObject.Methods(i)
    Method.Enabled = True
  Next

  ' Processes the object’s properties and calls the object’s methods
  MyObject.Run

  ' Deletes the method added to the object
  MyObject.DeleteMethod("ObjectMethod")

End Sub

DelphiScript

procedure ObjectSample();
var NewClass, MyObject, Method, i;
begin

  // Declares a new class
  NewClass := ODT.Classes.Declare('NewClass');
  // Adds properties and methods to the new class
  NewClass.AddProperty('Property1', 10);
  NewClass.AddProperty('Property2', 'Sample');
  NewClass.AddMethod('ClassMethod', 'Unit1.Test1');

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

  // Iterates through the object’s methods and enables them
  for i := 0 to MyObject.MethodCount - 1 do
  begin
    Method := MyObject.Methods[i];
    Method.Enabled := true;
  end;

  // Processes the object’s properties and calls the object’s methods
  MyObject.Run;

  // Deletes the method added to the object
  MyObject.DeleteMethod('ObjectMethod');

end;

C++Script, C#Script

function ObjectSample()
{

  var NewClass, MyObject, Method;
  // Declares a new class
  NewClass = ODT["Classes"]["Declare"]("NewClass");
  // Adds properties and methods to the new class
  NewClass["AddProperty"]("Property1", 10);
  NewClass["AddProperty"]("Property2", "Sample");
  NewClass["AddMethod"]("ClassMethod", "Unit1.Test1");

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

  // Iterates through the object’s methods and enables them
  for (var i = 0; i < MyObject["MethodCount"]; i++)
  {
    Method = MyObject["Methods"](i);
    Method["Enabled"] = true;
  }

  // Processes the object’s properties and calls the object’s methods
  MyObject["Run"]();

  // Deletes the method added to the object
  MyObject["DeleteMethod"]("ObjectMethod");

}

See Also

DeleteMethod Method
Methods Property
AddMethod Method
DeleteProperty Method
Method Object

Highlight search results