[fpc-devel] New feature discussion: for-in loop
Paul Ishenin
webpirat at mail.ru
Sun Oct 25 08:41:13 CET 2009
Graeme Geldenhuys wrote:
> Also, I referred to them in my implementation as Iterators - as per
> the Iterator design pattern. How does Enumerator differ from Iterator?
>
I have looked at you interfaces. They are needs to be changed a bit to
use then in the for-in loop. For example:
ITBIterator = interface(IInterface)
['{9C2BC10D-54C8-4B59-88B5-A564921CF0E3}']
function HasNext: Boolean;
function Next: TObject;
function HasPrevious: Boolean;
function Previous: TObject;
end;
To use it in the for-in loop you need to add a function MoveNext:
Boolean (you can choose any other name but you need to mark it using
'enumerator MoveMext' modifier) and property Current: TObject (you can
choose any other name but you need to mark it using 'enumerator Current'
modifier).
Look at
http://svn.freepascal.org/svn/fpc/branches/paul/features/tests/test/tforin8.pp
and
http://svn.freepascal.org/svn/fpc/branches/paul/features/tests/test/tforin9.pp
for examples.
Best regards,
Paul Ishenin.
More information about the fpc-devel
mailing list