Hi,

I've got a question on how does "Supports" function work. Here is the
quote from the FPC docs:

> Check whether a class or given interface supports an interface.
> Supports checks whether Instance supports the interface identified by IID. It 
> returns True
> if it is supported, False. Optionally, a pointer to the interface is returned 
> to Intf.

Suppose I have the code like this:

> IMyBasicInterface = interface
>  ['{B6F77975-0C46-4B09-9682-CE96C4CA465A}']
>  procedure DoSomething;
> end;
>
> IMyExtendedInterface = interface(IMyBasicInterface)
>   ['{DF214D0F-7B92-487F-B21A-4698B1E044AC}']
>   procedure DoSomethingElse;
> end;
>
> TMyClass = class(IInterfacedObject, IMyExtendedInterface)
>   procedure DoSomething;
>   procedure DoSomethingElse;
> end;
>
> var
>   MyClassInstance: TMyClass;

The following call returns True as expected:
> Supports(MyClassInstance, IMyExtendedInterface);

But this one returns False, that seems strange for me:
> Supports(MyClassInstance, IMyBasicInterface);

"Supports" does not seem to take into account interfaces inheritance,
so to make the second call work as expected, I have to change TMyClass
declaration to

> TMyClass = class(IInterfacedObject, IMyBasicInterface, IMyExtendedInterface)

So the questions are:
1) Is this an expected behavior?
2) Are there any detailed documentation to read on this subject? I have
not found anything, "Supports" is not very google-friendly name :(

Thanks in advance.

---
Vladimir.

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to