In our previous episode, Michael Van Canneyt said: > >> finally > >> it.Free; > >> end; > >> > >> Now, that is quite e few keystrokes to save, not to mention that > >> if item value is used more than once in the loop, SomeClass.NextValue must > >> be > >> stored in a variable, further bloating code. > > The above is only for classes. No-one said that the iterator must be a > class (e.g. objects are stored on the stack), so it can be reduced to: > > var > it: TSomethingIterator; > > it := SomeClass.Iterator; > while it.HaveValue do > it.NextValue.Something;
Lightcontainers does something like this, but uses function syntax based on records. HaveValue and NextValue are inline. One could see such constructs using D2006 methods-in-records syntax though, and afaik I have even seen it in the Delphi fora. _______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel