Name Property

Applies to TestComplete 15.42, last modified on September 08, 2022

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 MethodDeclaration.Name property to specify the name of the ODT class method. Note that if you rename a class method, the method will also be renamed in all objects that are based on this class.

Declaration

MethodDeclarationObj.Name

Read-Write Property String
MethodDeclarationObj An expression, variable or parameter that specifies a reference to a MethodDeclaration object

Applies To

The property is applied to the following object:

Property Value

A string that holds the method name.

Remarks

When changing this property, keep in mind that the method name must be unique within the class to which the method belongs. If the class already contains another method or property with the same name, an error will occur. Also, the method name is used to call the method in scripts. Therefore, the method name must match the naming rules of the project scripting languages (it must be a valid identifier). Otherwise, the scripts will not work.

Example

The following code snippet obtains the MethodDeclaration object and changes the method’s name.

JavaScript

function MethodDeclarationSample()
{
let ClassObj, MethodDecl;
  // Obtains the ODT class by its name
  ClassObj = ODT.Classes.Items("NewClass");
  // Obtains the declaration of the class method by the method’s index
  MethodDecl = ClassObj.Methods(0);
  let NewName = "ClassNewName";

  try
  {
    // Specifies the method’s new name
    MethodDecl.Name = NewName;
  }
  catch(e)
  {
  // If the method with the specified name already exists, posts an error message
    Log.Error(e.message);
  }

}

JScript

function MethodDeclarationSample()
{
var ClassObj, MethodDecl;
  // Obtains the ODT class by its name
  ClassObj = ODT.Classes.Items("NewClass");
  // Obtains the declaration of the class method by the method’s index
  MethodDecl = ClassObj.Methods(0);
  var NewName = "ClassNewName";

  try
  {
    // Specifies the method’s new name
    MethodDecl.Name = NewName;
  }
  catch(e)
  {
  // If the method with the specified name already exists, posts an error message
    Log.Error(e.description);
  }

}

VBScript

Sub MethodDeclarationSample

  ' Obtains the ODT class by its name
  Set ClassObj = ODT.Classes.Items("NewClass")
  ' Obtains the declaration of the class method by the method’s index
  Set MethodDecl = ClassObj.Methods(0)
  NewName = "ClassNewName"

  On Error Resume Next
    ' Specifies the method’s new name
    MethodDecl.Name = NewName
  If Err.Number <> 0 Then
  ' If the method with the specified name already exists, posts an error message
    Log.Error Err.Description
  End If

End Sub

DelphiScript

procedure MethodDeclarationSample();
var
  ClassObj, MethodDecl : OleVariant;
  NewName : string;
begin
  // Obtains the ODT class by its name
  ClassObj := ODT.Classes.Items['NewClass'];
  // Obtains the declaration of the class method by the method’s index
  MethodDecl := ClassObj.Methods[0];
  NewName := 'ClassNewName';

  try
    // Specifies the method’s new name
    MethodDecl.Name := NewName;
  except
  // If the method with the specified name already exists, posts an error message
    Log.Error(ExceptionMessage);
  end;

end;

C++Script, C#Script

function MethodDeclarationSample()
{
var ClassObj, MethodDecl;
  // Obtains the ODT class by its name
  ClassObj = ODT["Classes"]["Items"]("NewClass");
  // Obtains the declaration of the class method by the method’s index
  MethodDecl = ClassObj["Methods"](0);
  var NewName = "ClassNewName";

  try
  {
    // Specifies the method’s new name
    MethodDecl["Name"] = NewName;
  }
  catch(e)
  {
  // If the method with the specified name already exists, posts an error message
    Log["Error"](e["description"]);
  }

}

See Also

Class Object
Name Property
ScriptProc Property

Highlight search results