我有这些类和一个过程:
TParent = class(TObject);
TChild1 = class(TParent);
TChild2 = class(TParent);
Procedure DoSomething(obj:TParent);
我想要做的是,当obj
是一个TParent
并且不是后代时抛出异常。
我考虑了像这样做:
if obj.classname = TParent.classname then raise exception.create....
但它似乎有点hackish(TM)
更多信息:我的意图是能够传递具有共同属性/过程的对象。经过更多思考,TParent对象并不是真正需要的,我需要的是我在答案中展示的接口对象。