-1

I'm using Delphi XE3 and I don't understand why the first cast below does not compile :(

type
  TBase = class
  end;

  TDerived = class(TBase)
  end;

 procedure cast();
 var
   bases : TObjectList<TBase>;
   deriveds : TObjectList<TDerived>;

 begin
   bases := deriveds; // specific to generid, Here !
   deriveds := bases; // generic to specific, ok should not compile as is !
 end;
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
mderie
  • 35
  • 2

1 Answers1

0

It's simple: These are two different types, and are incompatible. The whole idea of Generics is to make typecasting strict, and the compiler is doing exactly what it's designed to do - prevent you from mixing types up.

Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327