[fpc-devel] language extensions
djbutler at gmail.com
Thu Jun 14 11:53:38 CEST 2007
Delphi supports iterator for the "for in" in different ways:
* Dynamic arrays, static arrays, sets, strings and records have "built-in"
* For classes and interface it requires a method called "GetEnumerator".
GetEnumerator can return a class, an interface or a record. This class,
interface or record must have a member called "MoveNext" and a property
called "Current". MoveNext returns a Boolean and Current returns the item.
You can for example do the following with a dynamic array:
TDoubleArray = array of Double;
A : TDoubleArray;
D : Double;
A := TDoubleArray.Create(1.0, 2.1, 3.2);
for D in A do
On 14/06/07, Bram Kuijvenhoven <kuifwaremailinglists at xs4all.nl> wrote:
> Daniël Mantione wrote:
> > Op Thu, 14 Jun 2007, schreef Florian Klaempfl:
> >> Graeme Geldenhuys schrieb:
> >>> I like the "for-in" code.
> >> Using the default property is clean, using count imo not. Thought I
> >> admit I've no idea so far to do it better.
> > Well, there already is a ";default;" directive, we could add a
> > directive.
> Something like that would be nice, but maybe an even nicer approach would
> property Items[index:Integer] read GetItem write SetItem low GetLow high
> or (to be more friendly to legacy code parsers)
> property Items[index:Integer] read GetItem write SetItem; low GetLow; high
> Then you can use Low(object.Items) and High(object.Items), even
> Low(object) if Items is the default property.
> If you stick with the 'Count' concept, I'd opt for
> property Items[index:Integer] read GetItem write SetItem; count GetCount;
> property Items[index:Integer] read GetItem write SetItem; count FCount;
> property Items[index:Integer] read GetItem write SetItem; length
> property Items[index:Integer] read GetItem write SetItem; size GetSize;
> To support properties that cannot be indexed by simple ordinals, an
> iterator mechanism could be added, like
> property Items[key:string]; iterator GetIterator;
> where GetIterator must return e.g. an IIterator interface, which is then
> to be defined in Objpas or the like, much like IUnkown.
> Add support for all this to the RTTI and you can even use it in streaming,
> scripting engines etc.
> fpc-devel maillist - fpc-devel at lists.freepascal.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-devel