TMyDataList<T: TBaseDatafile, constructor> = class(TObjectList<TBaseDatafile>)
public
constructor Create;
procedure upload(db: TDataSet);
end;
I read in a blog post (I don't remember where now) that this is the way to declare a generic-based class with a specific base type for the generic object. And the compiler will accept it just fine. But when I try to use it, it decides not to cooperate.
type
TDescendantList = TMyDataList<TDescendantDatafile>;
This gives me a compiler error.
[DCC Error] my_database.pas(1145): E2010 Incompatible types: 'TDescendantDatafile' and 'TBaseDatafile'
Thing is, 1145 isn't even a valid line. The file in question ends at #1142, and the type declaration that it's complaining about is on line #20. This makes me wonder if it's a compiler glitch. Or do I just not quite have the syntax right? Does anyone know a way to make this work?
EDIT: Jim pointed out that it compiles fine when he tried it. A bit more information: I have the base datafile type and the generic list declared in the same unit, while TDescendantDatafile is in a second unit and TDescendantList is defined in a third one. I've already found and reported one bug in D2009's compiler involving generics screwing up types across multiple units. This may be related. Can anyone confirm this?