[fpc-devel] Iterator for array properties
Michael Van Canneyt
michael at freepascal.org
Sat Oct 10 12:30:59 CEST 2015
On Sat, 10 Oct 2015, Ondrej Pokorny wrote:
> When we are already discussing new language features, what about supporting
> iterators for array properties:
> TTest = class
> // ...
> property Objects[Index: Integer]: TObject read GetObject *iterator
> property ObjectCount: Integer read GetObjectCount;
> This would allow code like:
> for MyObject in Test.Objects do
> In the LCL, e.g.:
> procedure TForm1.Button1Click(Sender: TObject);
> Comp: TComponent;
> for Comp in Components do
> This should actually be pretty OK and should not cause any regressions.
I'm all for it.
I've been looking how to implement names/objects/values enumerators in TStrings.
This would be the almost perfect solution.
But your example is not well-chosen, since the enumerator for TComponent already exists:
Procedure TForm1.Button1Click(Sender: TObject);
for Comp in Self do
Just as an aside...
More information about the fpc-devel