Sign in Join
FPDoc Onlineexperiment

IEnumerator interface

In unit System

Enumerator support interface.

Declaration

pascal
IEnumerator = class(IInterface)

Inheritance

  1. IEnumerator
  2. IInterface

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.

See also

Properties

CurrentReturn the current item.

Methods

GetCurrentReturns the current element in the iteration cycle.
MoveNextMove to the next value.
ResetReset the pointer.

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.