views:

215

answers:

2

I've got a custom TObjectList descendant in Delphi 2009, and I'd like to play with its enumerator a bit and add some filtering functionality to the MoveNext method, to cause it to skip certain objects. MoveNext is called by DoMoveNext, which is a virtual method, so this shouldn't be difficult to override... except for one thing. The TEnumerator for TObjectList isn't its own class; it's declared as a nested type within the TObjectList declaration.

Is there any simple way to override TEnumerator.DoMoveNext in my descendant class, or do I have to reimplement the whole TEnumerator? It's not a very big class, but I'd prefer to keep redundancies to a minimum if I can...

+8  A: 

The enumerator is its own class. It just has a nested scope. To write a descendant for it, you simply declare a class as you normally would, and when you specify the new class's ancestor, you give the fully qualified type name.

type
  TMasonEnumerator = class(TObjectList.TEnumerator)
  protected
    function DoMoveNext: Boolean; override;
  end;
Rob Kennedy
A: 

Excelent topics about enumerators.

DiGi
Thanks :) But I didn't cover that particular topic.
gabr