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 ";counter;"
directive.
Something like that would be nice, but maybe an even nicer approach would be
property Items[index:Integer] read GetItem write SetItem low GetLow high
GetHigh;
or (to be more friendly to legacy code parsers)
property Items[index:Integer] read GetItem write SetItem; low GetLow; high
GetHigh;
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;
Alternatives:
property Items[index:Integer] read GetItem write SetItem; length GetLength;
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.
Regards,
Bram
_______________________________________________
fpc-devel maillist - [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-devel