Name Property

Applies to TestComplete 14.0, last modified on January 23, 2019

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

Declaration

PropertyDeclarationObj.Name

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

Applies To

The property is applied to the following object:

Property Value

A string that holds the property name.

Remarks

When changing the PropertyDeclaration.Name property, keep in mind that the property name must be unique within the class to which the property belongs. If the class already contains another property or method with the same name, an error will occur. Also, the property name is used to refer to the property in scripts. Therefore, the property 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 example demonstrates how to obtain the property declaration and change the property name.

JavaScript

function PropertyDeclarationSample()
{

  let SampleClass, PropDeclObj;
  // Obtains the existing class by its name
  SampleClass = ODT.Classes.Items("SampleClass");
  // Obtains the declaration of the class property
  PropDeclObj = SampleClass.Properties("PropertyName");
  try
  {
    // Renames the property
    PropDeclObj.Name = "NewPropertyName";
  }
  catch(e)
  {
    Log.Error(e.message);
  }

}

JScript

function PropertyDeclarationSample()
{

  var SampleClass, PropDeclObj;
  // Obtains the existing class by its name
  SampleClass = ODT.Classes.Items("SampleClass");
  // Obtains the declaration of the class property
  PropDeclObj = SampleClass.Properties("PropertyName");
  try
  {
    // Renames the property
    PropDeclObj.Name = "NewPropertyName";
  }
  catch(e)
  {
    Log.Error(e.description);
  }

}

VBScript

Sub PropertyDeclarationSample

  Dim SampleClass, PropDeclObj
  ' Obtains the existing class by its name
  Set SampleClass = ODT.Classes.Items("SampleClass")
  ' Obtains the declaration of the class property
  Set PropDeclObj = SampleClass.Properties("PropertyName")
  Err.Clear
  On Error Resume Next
    ' Renames the property
    PropDeclObj.Name = "NewPropertyName"
  If Err.Number <> 0 Then
    Log.Error Err.Description
  End If
End Sub

DelphiScript

procedure PropertyDeclarationSample();
var SampleClass, PropDeclObj;
begin

  // Obtains the existing class by its name
  SampleClass := ODT.Classes.Items['SampleClass'];
  // Obtains the declaration of the class property
  PropDeclObj := SampleClass.Properties['PropertyName'];
  try
    // Renames the property
    PropDeclObj.Name := 'NewPropertyName';
  except
    Log.Error(ExceptionMessage);
  end;

end;

C++Script, C#Script

function PropertyDeclarationSample()
{

  var SampleClass, PropDeclObj;
  // Obtains the existing class by its name
  SampleClass = ODT["Classes"]["Items"]("SampleClass");
  // Obtains the declaration of the class property
  PropDeclObj = SampleClass["Properties"]("PropertyName");
  try
  {
    // Renames the property
    PropDeclObj["Name"] = "NewPropertyName";
  }
  catch(e)
  {
    Log["Error"](e["description"]);
  }

}

See Also

Class Object
Name Property
Value Property

Highlight search results