Supports() only checks declared interfaces?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Supports() only checks declared interfaces?

Michalis Kamburelis-3
Hi,

Consider the attached source code. I have a base interface (IA) and a
descendant interface (IB). Class TB is declared as

  TB = class(TInterfacedObject, IB) end;

Now I would expect that both

  Supports(TB, IA)
  Supports(TB, IB)

return true. After all, TB is forced to implement methods of both IA and
IB, as IB descends from IA. But to my surprise, Supports(TB, IA) returns
false.

Changing the declaration to

  TB = class(TInterfacedObject, IA, IB) end;

workarounds the problem (Supports(TB, IA) returns true), but seems
strange in my opinion.

I haven't found any explanation for this e.g. in docs
(http://freepascal.org/docs-html/rtl/sysutils/supports.html ,
http://freepascal.org/docs-html/ref/refch7.html ).

Is this the expected behavior? Documented anywhere? Or is this a bug,
and I should submit it?

Thanks,
Michalis

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

a.pas (473 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Supports() only checks declared interfaces?

Paul Ishenin-2
06.01.2011 20:14, Michalis Kamburelis wrote:

> return true. After all, TB is forced to implement methods of both IA and
> IB, as IB descends from IA. But to my surprise, Supports(TB, IA) returns
> false.
>
> Changing the declaration to
>
>    TB = class(TInterfacedObject, IA, IB) end;
>
> workarounds the problem (Supports(TB, IA) returns true), but seems
> strange in my opinion.
>
> I haven't found any explanation for this e.g. in docs
> (http://freepascal.org/docs-html/rtl/sysutils/supports.html ,
> http://freepascal.org/docs-html/ref/refch7.html ).
>
> Is this the expected behavior? Documented anywhere? Or is this a bug,
> and I should submit it?
This is expected behavior. It works the same way as in delphi.

Best regards,
Paul Ishenin
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Supports() only checks declared interfaces?

Michalis Kamburelis-3
Paul Ishenin wrote:
> 06.01.2011 20:14, Michalis Kamburelis wrote:
>> return true. After all, TB is forced to implement methods of both IA and
>> IB, as IB descends from IA. But to my surprise, Supports(TB, IA) returns
>> false.

> This is expected behavior. It works the same way as in delphi.
>

Thank you.

So, the natural next question: is there some construct similar to the
Supports() function, that avoids this problem? That is, something that
detects that class TB supports both IA and IB interfaces, even though
it's declared only as "TB = class(TInterfacedObject, IB)" ?

Or is my only choice to just declare "TB = class(TInterfacedObject, IA,
IB)" ?

Michalis
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Supports() only checks declared interfaces?

Paul Ishenin-2
06.01.2011 23:25, Michalis Kamburelis wrote:
> So, the natural next question: is there some construct similar to the
> Supports() function, that avoids this problem? That is, something that
No.
> detects that class TB supports both IA and IB interfaces, even though
> it's declared only as "TB = class(TInterfacedObject, IB)" ?
TB is declared as it only implements IB.
> Or is my only choice to just declare "TB = class(TInterfacedObject, IA,
> IB)" ?
Yes.

Best regards,
Paul Ishenin
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal