What I would like to achieve is along the lines of:
type
TAncestor = class
FData: TArray<???>;
// ...
// A lot of methods that load, export, change FData
// in a way common to all the descendants (mostly Length
// and SetLength are used)
//
// Differences in managing FData are extracted into
// protected virtual methods
// ...
end;
TAncestorClass = class of TAncestor;
TDescendant1 = class(TAncestor)
type
TItem = ... // Some type
// ...
// Virtual methods that do descendant-specific things
// are overriden here
// ...
end;
TDescendant2 = class(TAncestor)
type
TItem = ... // Another type
// ...
// Virtual methods that do descendant-specific things
// are overriden here
// ...
end;
...
The TItem-specific code is all in descendants, TAncestor just implements general management of how and when to resize FData and provides boilerplate code for loading, exporting and performing container-level changes on the data thatwould otherwise be duplicated in every descendant.
This could probably be achieved with generics (descending from TAncestor<T> with particular T for each descendant), but this approach fails to support metaclasses and nested types. Am I missing something or is this not possible?