I believe it's a fault in the compiler. If you debug it it actually will show the object as Isecond, even though The variable is declared as Ifirst. The code will never crash because all the methods of Ifirst must exist in an Isecond.
I wouldn't rely on future versions of Delphi keeping the "Bug/Feature" though. It is always safer to use the "as" operator to do casting rather than use an idiosynchs of delphi perhaps :) -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Conor Boyd Sent: Monday, 16 June 2003 4:40 p.m. To: Multiple recipients of list delphi Subject: RE: [DUG]: Interface Inheritance Mmmm, I haven't got time right now to try it, but that's not the behaviour I'd expect. I'd have hoped the compiler would pick that up, as it appears to with your second example. Interesting, can't explain it... C. -----Original Message----- From: Todd Martin [mailto:[EMAIL PROTECTED] However I noticed one very peculiar aspect of interfaces along the way when compiling. If I define a procedure DoSomething(AObject : IFirstDescendant); and TNewClass = class(TInterfacedObject,ISecondDescendant); and then the following code compiles okay procedure Test; var MyObject : ISecondDescendant; begin MyObject := TNewClass.Create; DoSomething(MyObject); end; I haven't checked yet, but I'm assuming the MyObject passed through to procedure DoSomething() is then "nil", since TNewClass doesn't support IFirstDescendant. Would that be your guess too? So why does it compile? On the otherhand, does the ISecondDescendant pointer get sucessfully converted to a IFirstDescendant pointer, in which case, why does MyObject.QueryInterface(IFirstDescendant,FirstObject) return a "nil" pointer to FirstObject? However, if I define IFirstDescendant = interface(IInterface); ISecondDescendant = interface(IInterface); ie. no interface inheritance - (or whatever you want to call it) and TNewClass = class(TInterfacedObject,IFirstDescendant,ISecondDescendant); the Test() procedure does not compile. Any comments? ------------------------------------------------------------------------ --- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi" Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/ --------------------------------------------------------------------------- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi" Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
