如何重写嵌套类型的方法?
我在 Delphi 2009 中有一个自定义的 TObjectList 后代,我想稍微玩一下它的枚举器,并向 MoveNext 方法添加一些过滤功能,以使其跳过某些对象。 MoveNext 由 DoMoveNext 调用,这是一个虚拟方法,因此重写它应该不难......除了一件事。 TObjectList 的 TEnumerator 不是它自己的类; 它在 TObjectList 声明中声明为嵌套类型。
有没有简单的方法可以在我的后代类中重写 TEnumerator.DoMoveNext,或者我是否必须重新实现整个 TEnumerator? 这不是一个很大的班级,但如果可以的话,我希望将裁员降到最低......
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
枚举器是它自己的类。 它只有一个嵌套范围。 要为其编写后代,只需像平常一样声明一个类,然后在指定新类的祖先时,就给出完全限定的类型名称。
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.
关于枚举器的优秀主题。
Excelent topics about enumerators.