I want to implement a generic class,TB, which inherits from another generic class, TA, something like the following:generic TA<T>= class (TObject)end;generic TB<T>= class (TA<T>)end;But it does not work! Any idea how I can do that.
generic TA<A> = class(TOBject) end; _TA = specialize TA<TObject>; generic TB<B> = class(_TA) end;
TAbstractQueue = class(TObject) procedure insert (Data: TObject); virtual; abstract;end;generic TGenericQueue<Q> = class(TAbstractQueue) // Overridden from base class procedure insert(Data: TObject); override; // generic-specific procs..end;
type TDoubleQueue= specialize TGenericQueue<Double>;......var Q: TAbstractQueue; DPtr: PDouble;begin ... Q:= TDoubleQueue.Create; .... New (DPtr); Dptr^:= 1.2; Q.Insert (TObject (DPtr)); ...end;
TList<TIndexType, TItemType> = classprivate Items: array[TIndexType] of TItemType; ...public methods... properties...end;
TByteList = TList<Integer, Byte>TStringList = TList<Integer, string>TObjectList = TList<Integer, TObject>
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>
TList<TIndexType,TItemType> = class Items: Pointer; Size: TIndexType; ...end;TOrderedList<TIndexType,TItemType> = classendTIntegerList<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;
generic TList<TItemType> = classend;generic TMyList<TItemType> = class(TList); // Error: Generics without specialization can not be used as a type for a variablegeneric TMyList<TItemType> = class(TList<TItemType>); // Error: Generics without specialization can not be used as a type for a variablegeneric TMyList<TItemType> = class(generic TList<TItemType>); // Error: Identifier not found "generic"generic TMyList<TItemType> = class(specialize TList<TItemType>); // Error: Identifier not found "TItemType"
eny: I hope you saw the problem.