[fpc-pascal] a few trivial questions

spir ☣ denis.spir at gmail.com
Wed May 12 19:07:49 CEST 2010


On Wed, 12 May 2010 17:19:57 +0200
Graeme Geldenhuys <graemeg.lists at gmail.com> wrote:

> 2010/5/12 spir ☣:
> >
> > * TFPList
> > Is there another way to traverse a list than
> >    for i :=0 to (list.count - 1) do ...
> > What about list.high?
> 
> Yes, I use the Iterator design pattern. This allows me to write code as follows:
> 
> ---------------
> var
>   itr: ITBStringIterator;
> begin
>   ...
>   itr := gIteratorFactory.StringIterator(sl);
>   while itr.HasNext do
>      writeln(itr.Next);
>    ...
> end;
> ---------------
> 
> I have created Iterators for all existing list types and the code (and
> accompanied article explaining Iterators) are freely available at:
> http://opensoft.homeip.net/articles/
> 
> Iterators have the added flexibility that I can even combine them with
> regular expressions to creating a filtered list.
> -----------
> fitr := gIteratorFactory.FilteredStringIterator(MyStringsCollection, 'foob.*r');
> while fitr.HasNext do
> begin
>   DoSomethingWithItem(fitr.Next);
>   ...
> end;
> -----------
> 
> I can also move backwards, forwards, peak back or forward, reverse the
> iterating, reset the iteration etc. Iterators are very flexible.

Oh, thank you for this pattern. This is a really nice feature, esp. in that it integrates so well with while loops?
I'll have a look at your code as soon as I can.


Denis
________________________________

vit esse estrany ☣

spir.wikidot.com



More information about the fpc-pascal mailing list