Generic class inheritance is if fact necessary to build good general classes.
For example could need common TList similar to array costruction. Definition of array is composed from index type and item type so generic TList should look like:
TList<TIndexType, TItemType> = class
private
Items: array[TIndexType] of TItemType;
...
public
methods...
properties...
end;
Than some specialised types could be defined as:
TByteList = TList<Integer, Byte>
TStringList = TList<Integer, string>
TObjectList = TList<Integer, TObject>
Index range could be scaled to:
TShortStringList = TList<ShortInt, string>
TSmallStringList = TList<Small, string>
TLongStringList = TList<LongInt, string>
THugeStringList = TList<Int64, string>
TCustomSizeStringList = TList<0..10, string>
TColorStringList = TList<TColor, string>
But in Delphi index type require ordinal type so it can't be fully general class. Maybe it could be solved using some type constrains.
Next requirements is inheritance...
TList<TIndexType,TItemType> = class
Items: Pointer;
Size: TIndexType;
...
end;
TOrderedList<TIndexType,TItemType> = class
end
TIntegerList<TIndexType> = class(TList<TIndexType, Integer>);
TCapacityGenericList<TIndexType,TItemType> = class(TList<TIndexType,TItemType>)
Capacity: TIndexType; // Less realocations
...
end;
TStack<TIndexType,TItemType> = class(TList<TIndexType,TItemType>)
procedure Push(Item: TItemType);
function Pop: TItemType;
end;
TQueue<TIndexType,TItemType> = class(TList<TIndexType,TItemType>)
procedure Push(Item: TItemType);
function Pop: TItemType;
end;
TMyGenericQueue<TIndexType,TItemType> = class(TQueue<TIndexType,TItemType>)
...
end;
So to build wide usable common classes we need inheritance as well.
But in FPC similar constructs not work.
generic TList<TItemType> = class
end;
generic TMyList<TItemType> = class(TList); // Error: Generics without specialization can not be used as a type for a variable
generic TMyList<TItemType> = class(TList<TItemType>); // Error: Generics without specialization can not be used as a type for a variable
generic TMyList<TItemType> = class(generic TList<TItemType>); // Error: Identifier not found "generic"
generic TMyList<TItemType> = class(specialize TList<TItemType>); // Error: Identifier not found "TItemType"