With my blog posting last week on Delphi – class helper to add for … in support for TComponent.Components/ComponentCount I ‘lied’ a bit.
What I actually wanted to do was write code like this:
for Component in Self.ComponentsOfType(TSQLQuery) do (Component as TSQLQuery).SQL[1] := FTableName;
This filters the enumeration to only enumerate components that are of type TSQLQuery or descend from type TSQLQuery.
So I wanted to write a ‘richer’ enumerator than just iterating over all components.
The scond part of the lie is that such an enumerator in fact already exists: there is already a TComponent.GetEnumerator method.
Primoz Gabrijelcic’s – web/blog – rightly noted in the comment where he pointed to a similar blog post he wrote for TControls.
Since I wrote this post last week as well, but scheduled to be published right before DelphiLive!, I just added a reference to his comment, site, blog and posting.
TComponent already has a GetEnumerator since Delphi 2006.
But my TComponentEnumerator was meant as a base class to show you how to descend from it.
And that’s what this blog post is about.
Read the rest of this entry »