Skip to content

IEnumerator

[Properties (by Name)][Methods (by Name)][Events (by Name)]

Enumerator support interface

Declaration

Source position: objpash.inc line 275

Type
  IEnumerator = interface (IInterface)
    function GetCurrent : TObject;
    function MoveNext : Boolean;
    procedure Reset;
    Current : TObject;
  end
  ;

Description

IEnumerator is the interface needed by the For ... in ... language construct, when operating on classes. It contains all methods that the compiler needs to implement a loop.

A for in loop like the following:

For O in MyObject do
  begin
  // do things
  end;

is treated by the compiler as equivalent to the following code:

Var
  I : IEnumerator;
  O : TObject;

begin
  I:=MyObject.GetEnumerator;
  While I.MoveNext do
    begin
    O:=I.GetCurrent;
    // Do things
    end; 
end.  

Any class that implements the IEnumerable interface must be able to return an IEnumerator instance for the compiler to use in a For in loop.

Members

Member Type Visibility Description
Current Property default Return the current item
GetCurrent Method default Returns the current element in the iteration cycle
MoveNext Method default Move to the next value
Reset Method default Reset the pointer

Inheritance

Class Description
IEnumerator Enumerator support interface

See also

Name Description
IEnumerable Interface to retrieve an enumerator from a class.
TObject Base class of all classes.