[fpc-pascal] Interface type error
Sven Barth
pascaldragon at googlemail.com
Sun Feb 2 09:23:55 CET 2020
Ryan Joseph via fpc-pascal <fpc-pascal at 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20200202/3c6d823c/attachment.html>
More information about the fpc-pascal
mailing list