Does Delphi provide any nice way to iterate over TCollectionItems in a TCollection?
Something, perhaps, along the lines of...
for mycollectionitem in mycollection.Items do
mycollectionitem.setWhatever();
That doesn't compile though
or is there really nothing I can do that's more elegant than this:
for num := 1 to mycollection.Count do
mycollection.Items[num-1].setWhatever();
For..inloops are implemented as calls toGetEnumeratorand the methods on the variable it returns. TheItemsproperty is not an object, but an array property that maps silently to a getter/setter pair, so it can't return an enumerator, butTCollectionitself does have aGetEnumeratormethod.Thus:
Be aware, though, that
TCollectionis not a generic class, so the type of the enumerator index variable will beTCollectionItem, and not whateverItemClassyou're working with.