Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-01

Supports() only checks declared interfaces?

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michalis Kamburelis

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

Paul Ishenin
to Michalis Kamburelis
Michalis Kamburelis wrote 17 lines
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

Michalis Kamburelis
to Paul Ishenin
Paul Ishenin wrote 7 lines
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

Paul Ishenin
to Michalis Kamburelis
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