DeleteVariable Method

Applies to TestComplete 14.70, last modified on April 22, 2021

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 Group.DeleteVariable method to delete a variable with the specified name from the group.

Declaration

GroupObj.DeleteVariable(Name)

GroupObj An expression, variable or parameter that specifies a reference to a Group 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 variable to be deleted. If the object group does not contain a variable with the specified name, an error occurs.

Result Value

None.

Example

The code below deletes all variables that aren't processed by the Run methods when they walk down the custom hierarchy, from the MyGroup group.

JavaScript, JScript

function DeleteVariable()
{
  // Obtains information about the group
  var Group = ODT.Data.MyGroup;
  var VarNum = Group.VariableCount;

  // Iterates through the variables
  for (var i = 0; i < VarNum; i++)
  {
    var Variable = Group.Variables(i);
    // Checks whether the variable is processed by the Run methods
    if (! Variable.Enabled)
    {
      // Deletes the variable
      Group.DeleteVariable(Variable.Name);
      // Updates counters
      i--;
      VarNum--;
    }
  }
}

VBScript

Sub DeleteVariable
  ' Obtains information about the group
  Set Group = ODT.Data.MyGroup
  VarNum = Group.VariableCount

  ' Iterates through the variables
  For i = 0 to (VarNum - 1)
    Set Variable = Group.Variables(i)
    ' Checks whether the variable is processed by the Run methods
    If Not Variable.Enabled Then
      ' Deletes the variable
      Group.DeleteVariable(Variable.Name)
      ' Updates counters
      i = i - 1
      VarNum = VarNum - 1
    End If
  Next

End Sub

DelphiScript

function DeleteVariable;
var Group, VarNum, i, Variable;
begin
  // Obtains information about the group
  Group := ODT.Data.MyGroup;
  VarNum := Group.VariableCount;

  // Iterates through the variables
  for i := 0 to (VarNum - 1) do
  begin
    Variable := Group.Variables[i];
    // Checks whether the variable is processed by the Run methods
    if not (Variable.Enabled) then
    begin
      // Deletes the variable
      Group.DeleteVariable(Variable.Name);
      // Updates counters
      Dec(i);
      Dec(VarNum);
    end;
  end;

end;

C++Script, C#Script

function DeleteVariable()
{
  // Obtains information about the group
  var Group = ODT["Data"]["MyGroup"];
  var VarNum = Group["VariableCount"];

  // Iterates through the variables
  for (var i = 0; i < VarNum; i++)
  {
    var Variable = Group["Variables"](i);
    // Checks whether the variable is processed by the Run methods
    if ( ! Variable["Enabled"] )
    {
      // Deletes the variable
      Group["DeleteVariable"]( Variable["Name"] );
      // Updates counters
      i--;
      VarNum--;
    }
  }
}

See Also

AddVariable Method
AddVarOfArrayType Method
AddVarOfClassType Method
Clear Method

Highlight search results