I have a generic list class:
TMyObjectlist<T: TMyObject> = class(TObjectList<T>);
and a derived list class:
TMyDerivedObjectList = class(TMyObjectList<TMyDerivedObject>);
I want to check if an instance MyList of TMyDerivedObjectList inherits from TMyObjectList, however:
MyList.InheritsFrom(TMyObjectlist<TMyObject>)
returns False.
It turns out that MyList.Classparent is of type TMyObjectList<TMyDerivedObject>
.
Does anybody knows how to check the InheritsFrom in this case?
Just draw up the inheritance scheme for both list objects and you'll clearly see why the InheritsFrom doesn't work. In Generics.Collections we have:
TEnumerable<T> = class abstract;
TList<T> = class(TEnumerable<T>);
TObjectList<T> = class(TList<T>);
In your example we have:
TMyObject = class;
TMyDerivedObject = class(TMyObject);
So we get those two inheritance trees:
TObject
|
TEnumerable<TMyDerivedObject>
|
TList<TMyDerivedObject>
|
TObjectList<TMyDerivedObject>
and then we have:
TObject
|
TEnumerable<TMyObject>
|
TList<TMyObject>
|
TObjectList<TMyObject>
As you can see, the only common ancestor for both list types is TObject!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With