Utils.Enumerator Method

Applies to TestComplete 15.46, last modified on January 09, 2023

Description

The Utils.Enumerator method returns the Enumerator object that lets you iterate through the items of the specified collection. This method is very useful if you use DelphiScript, since this scripting language does not support enumerators by default. It can also be used to iterate through a collection, no matter which language you use.

When you create an enumerator, it points to the first item of the collection. Use the MoveNext method to select the next item and the AtEnd method to check if the selected item is the last one.

Declaration

Utils.Enumerator(Object Collection)

Object Collection [in]    Required    Object    
Result An Enumerator object.

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Object Collection

A collection object.

For TestComplete objects, the _NewEnum property creates the collection and makes it accessible directly with enumerator.

Result Value

An Enumerator object that lets you enumerate items in the collection.

Example

The following code snippet creates an enumerator and moves it through the collection belonging to the Sys object:

JavaScript, JScript

function Test()
{
  // Create the enumerator
  var Enum = Utils.Enumerator(Sys);
  // Loop until the last item of the collection is selected
  while (!Enum.AtEnd)
  {
    // Do something
    // Move to the next item of the collection
    Enum.MoveNext()
  }
}

Python

def Test():
  # Create the enumerator
  Enum = Utils.Enumerator(Sys)
  # Loop until the last item of the collection is selected
  while not Enum.AtEnd():
    # Do something
    # Move to the next item of the collection
    Enum.MoveNext()

VBScript

Sub Test
  ' Create the enumerator
  Set enumproc = Utils.Enumerator(Sys)
  ' Loop until the last item of the collection is selected
  Do While not enumproc.AtEnd
    ' Do something
    ' Move to the next item of the collection
    enumproc.MoveNext
  Loop
End Sub

DelphiScript

procedure Test();
var
  Enum;
begin
  // Create the enumerator
  Enum := Utils.Enumerator(Sys);
  // Loop until the last item of the collection is selected
  while not Enum.AtEnd do
  begin
    // Do something
    // Move to the next item of the collection
    Enum.MoveNext();
  end;
end;

C++Script, C#Script

function Test()
{
  // Create the enumerator
  var Enum = Utils["Enumerator"](Sys);
  // Loop until the last item of the collection is selected
  while (!Enum["AtEnd"])
  {
    // Do something
    // Move to the next item of the collection
    Enum["MoveNext"]()
  }
}

See Also

Utils Object

Highlight search results