[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 
> GetObjectIterator*;
>    property ObjectCount: Integer read GetObjectCount;
>  end;
>
> This would allow code like:
>
>  for MyObject in Test.Objects do
>    //...
>
> In the LCL, e.g.:
>
> procedure TForm1.Button1Click(Sender: TObject);
> var
>  Comp: TComponent;
> begin
>  for Comp in Components do
>    //...
> end;
>
> This should actually be pretty OK and should not cause any regressions.

After a

sed s/iterator/enumerator/g

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);
  var
   Comp: TComponent;
  begin
   for Comp in Self do
     //...
  end;

Just as an aside...

Michael.



More information about the fpc-devel mailing list