Ryan Joseph via fpc-pascal <fpc-pascal@lists.freepascal.org> schrieb am So., 2. Feb. 2020, 03:37:
> Why doesn't this compile? IClassName2 descends from IClassName1 so > shouldn't TClassName be compatible with IClassName1? > > ======================================== > > {$mode objfpc} > {$interfaces corba} > > program test; > > type > IClassName1 = interface > end; > IClassName2 = interface(IClassName1) > end; > > type > TClassName = class(IClassName2) > end; > > procedure Pass(int: IClassName1); > begin > > end; > > var > c: TClassName; > begin > // Incompatible type for arg no. 1: Got "TClassName", expected > "IClassName1" > Pass(c); > end. > As I had explained in the other thread some months ago interfaces in Object Pascal mean literally that the type can be cast to the specified interfaces. Parent interfaces are *not* part of this. If you want this you need to first cast the class to IClassName2, then the "interface inheritance" mechanism can take over. Regards, Sven >
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal