The enumerator for TObjectList declared in TList , which is the class from which TObjectList is derived. RTL does not bother to declare a more specific counter for TObjectList . Thus, you are left with the TList enumerator. Which gives elements of type Pointer , which are the type of element stored in TList .
There are probably several reasons why RTL designers decided not to do anything with TObjectList . For example, I suggest the following potential causes:
TObjectList , like everything in Contnrs , is deprecated and deprecated by generic containers in Generics.Collections . Why waste resources changing an outdated class.- Even if the
TObjectList had an enumerator that gave the TObject elements, you still have to distinguish them. Would an enumerator that gave TObject be much more useful? - Designers simply forgot that this class existed when adding counters.
What you have to do. The obvious choice is to use TList<T> or TObjectList<T> from Generics.Collections . If you want to continue with TObjectList , you can subclass it and add an enumerator that would give TObject . If you do not know how to do this, you can learn how to do this from the documentation . Or you can use the inherited enumerator and the type thrown by the pointers it gives.
It seems to me that since you are ready to change the code from the indexed for loop to the for for loop, this means that you are ready to make unnecessary changes to the code. In this case, a common container would seem to be the obvious choice.
source share