[Lazarus] Iterate TStringToStringTree

Graeme Geldenhuys graemeg.lists at gmail.com
Tue Jun 15 17:21:54 CEST 2010


On 15/06/2010, Juha Manninen wrote:
>
> Thanks.
> Java shines with its container classes. Iterator interface and support for
> generics types are just cool. It all could be implemented with Object Pascal
> as well.

Yes, java is great in that way, but it was decided not to extend the
classes in the RTL with such functionality. So I implemented them as
external classes that gets created by a Factory Method, using a
lazyman's Singleton.

It can now be used as follows... Good news is that any iteration code
over any list class (object list, string list, tree view) now looks
the same. No need to know if the list class is 1-based or 0-based
etc.. The container/list class can now change internally, and no
iteration code needs to change either.

var
  itr: IStringIterator
begin
      itr := gIteratorFactory.StringIterator(lst);
      if Assigned(itr) then
      begin
        while itr.HasNext do
          Add(itr.Next);
      end;
      itr := nil;
end;


I think I made some changes to the units included with the article, so
I attached the latest ones I have.


-- 
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: iterator_intf.pas
Type: text/x-pascal
Size: 5147 bytes
Desc: not available
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20100615/ddae8c95/attachment-0004.pas>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: iterator_impl.pas
Type: text/x-pascal
Size: 11733 bytes
Desc: not available
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20100615/ddae8c95/attachment-0005.pas>


More information about the Lazarus mailing list