<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Ryan Joseph via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>> schrieb am So., 2. Feb. 2020, 03:37:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Why doesn't this compile? IClassName2 descends from IClassName1 so shouldn't TClassName be compatible with IClassName1?<br>
<br>
========================================<br>
<br>
{$mode objfpc}<br>
{$interfaces corba}<br>
<br>
program test;<br>
<br>
type<br>
IClassName1 = interface<br>
end;<br>
IClassName2 = interface(IClassName1)<br>
end;<br>
<br>
type<br>
TClassName = class(IClassName2)<br>
end;<br>
<br>
procedure Pass(int: IClassName1); <br>
begin<br>
<br>
end;<br>
<br>
var<br>
c: TClassName;<br>
begin<br>
// Incompatible type for arg no. 1: Got "TClassName", expected "IClassName1"<br>
Pass(c);<br>
end.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">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. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>