Re: [fpc-pascal] Interfaces inheritance and Supports routine
On Sun, 2 Nov 2008, Graeme Geldenhuys wrote: On Sun, Nov 2, 2008 at 6:31 PM, Vladimir Zhirov [EMAIL PROTECTED] wrote: 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 :( http://dn.codegear.com/article/29779 From this article it seems things have changed since Delphi 8 onwards. The last Delphi version I used was D7. :-) I don't know what delphi version FPC's features are based on. D5 or D7. All Delphis between D7 and D2007 were not real Delphis :-) Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Interfaces inheritance and Supports routine
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
Re: [fpc-pascal] Interfaces inheritance and Supports routine
On Sun, Nov 2, 2008 at 6:31 PM, Vladimir Zhirov [EMAIL PROTECTED] wrote: 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? I'm not an expert with Interfaces, but as far as I understood the documentation and from what I have seen in other code, that is expected behaviour. Below is information from the Kylix 3 help: ---[ kylix 3 help ]- An interface-type expression cannot reference an object whose class implements a descendant interface, unless the class (or one that it inherits from) explicitly implements the ancestor interface as well. For example, type IAncestor = interface end; IDescendant = interface(IAncestor) procedure P1; end; TSomething = class(TInterfacedObject, IDescendant) procedure P1; procedure P2; end; ... var D: IDescendant; A: IAncestor; begin D := TSomething.Create; // works! A := TSomething.Create; // error D.P1; // works! D.P2; // error end; In this example, A is declared as a variable of type IAncestor. Because TSomething does not list IAncestor among the interfaces it implements, a TSomething instance cannot be assigned to A. But if we changed TSomething's declaration to TSomething = class(TInterfacedObject, IAncestor, IDescendant) ...the first error would become a valid assignment. ---[ end ]- Regards, - Graeme - ___ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interfaces inheritance and Supports routine
On Sun, Nov 2, 2008 at 6:31 PM, Vladimir Zhirov [EMAIL PROTECTED] wrote: 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 :( http://dn.codegear.com/article/29779 From this article it seems things have changed since Delphi 8 onwards. The last Delphi version I used was D7. :-) I don't know what delphi version FPC's features are based on. Regards, - Graeme - ___ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal