DeleteProperty Method

Applies to TestComplete 15.69, last modified on November 13, 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

Deletes a property from the ClassObj object. Note that if you delete a property from a class, it will be deleted from all the objects that are based on this class.

Declaration

ClassObj.DeleteProperty(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 property to be deleted. If the class does not contain the property with the specified name, an error occurs.

Result Value

None.

Example

The code below deletes all the properties that belong to the MyClass class and have empty values from a project.

JavaScript, JScript

function DeletePropertyExample()
{
  // Specifies the class
  var MyClass = ODT.Classes.MyClass;
  // Obtains the total number of the class's properties
  var PropNum = MyClass.PropertyCount;
  
  // Iterates through the properties
  for (var i = 0; i < PropNum; i++)
  {
    var PropertyItem = MyClass.Properties(i);
    // Checks whether a property's value is empty
    if (PropertyItem.Value == aqObject.EmptyVariant)
    {
      // Deletes the property and updates the counters
      MyClass.DeleteProperty(PropertyItem.Name);
      i--;
      PropNum--;
    }
  }
  
}

VBScript

Sub DeletePropertyExample()

  ' Specifies the class
  Set MyClass = ODT.Classes.MyClass
  ' Obtains the total number of the class's properties
  PropNum = MyClass.PropertyCount
  
  ' Iterates through the properties
  for i = 0 to (PropNum - 1)
  
    Set PropertyItem = MyClass.Properties(i)
    ' Checks whether a property's value is empty
    If (PropertyItem.Value = aqObject.EmptyVariant) then
      ' Deletes the property and updates the counters
      MyClass.DeleteProperty(PropertyItem.Name)
      i = i - 1
      PropNum = PropNum - 1
    End If
  Next
  
End Sub

DelphiScript

function DeletePropertyExample;
var MyClass, PropNum, i, PropertyItem;
begin

  // Specifies the class
  MyClass := ODT.Classes.MyClass;
  // Obtains the total number of the class's properties
  PropNum := MyClass.PropertyCount;
  
  // Iterates through the properties
  for i := 0 to (PropNum-1) do
  begin
    PropertyItem := MyClass.Properties[i];
    // Checks whether a property's value is empty
    if (PropertyItem.Value = aqObject.EmptyVariant) then
    begin
      // Deletes the property and updates the counters
      MyClass.DeleteProperty(PropertyItem.Name);
      Dec(i);
      Dec(PropNum);
    end;
  end;
  
end;

C++Script, C#Script

function DeletePropertyExample()
{
  // Specifies the class
  var MyClass = ODT["Classes"]["MyClass"];
  // Obtains the total number of the class's properties
  var PropNum = MyClass["PropertyCount"];
  
  // Iterates through the properties
  for (var i = 0; i < PropNum; i++)
  {
    var PropertyItem = MyClass["Properties"](i);
    // Checks whether a property's value is empty
    if ( PropertyItem["Value"] == aqObject["EmptyVariant"] )
    {
      // Deletes the property and updates the counters
      MyClass["DeleteProperty"]( PropertyItem["Name"] );
      i--;
      PropNum--;
    }
  }
  
}

See Also

AddProperty Method
DeleteMethod Method
Properties Property
DeleteProperty Method
PropertyDeclaration Object

Highlight search results