<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">This code is working correctly/logically - and the same as it does in Delphi...<div><br></div><div><div>When using "implements" you are directing that this property "Intf" provides the interface "IIntf1" for your host object "TClass2" - and in TClass2.Create you create object "O: TClass1" to implement interface "IIntf1". Since "I1" requests the "IIntf1" interface, it is provided via "implements" and is therefore implemented by object "O". </div><div><br></div><div>When "I2:=C2 as IIntf2;" is executed, there is no "implements" property for this interface, so C2.GetInterface returns an "IIntf2" interface which it implements itself - and therefore "I2.Print" prints 3.</div><div><br></div><div>When "I2:=I1 as IIntf2;" is executed, this calls O.GetInterface (as "O" is the implementing object) requesting "IIntf2", which O does support, so the returned "IIntf2" interface is still implemented by "O". When calling "I2.Print", "O" as the implementing object returns 30.</div><div><br></div><div>When you comment out "implements", the only object implementing the interfaces you are working with is your main "C2" object - so 3 is the only value that can be returned.</div><div><br></div><div>Regards,</div><div><br></div><div>Andrew Hall.</div><div><br></div><div><br><div><div>On 22 Nov 09, at 04:24 , Denis Golovan wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div>I've got a non-obvious class hierarchy with interfaces involved.</div><div>The problem is that, I thought "property ... implements ...;" construction fully substitute for implementing interface methods in class itself, but now it's just not true.</div><div>I get different results in case implements is used and when it isn't.</div><div><br></div><div>If I comment implements implementation, my results are:</div><div><div>TClassBase.Print 3</div><div>TClassBase.Print 3</div><div>TClassBase.Print 3</div><div><br></div></div><div>If I use implements, my results are:</div><div><div>TClassBase.Print 3</div><div>TClassBase.Print 3</div><div>TClassBase.Print 30</div></div><div><br></div><div>See my example below.</div><div><br></div><div>I wonder if it is by design?</div><div>I have similar bug posted on bug tracker under <a href="http://bugs.freepascal.org/view.php?id=14842">http://bugs.freepascal.org/view.php?id=14842</a></div><div><br class="Apple-interchange-newline"></div></span></blockquote></div><br></div></div></body></html>