<div>Thanks for info.</div><div><br></div>Well. Now I see the technical reason for it. <div>I thought so too.</div><div><br></div><div>Sure, I'm not a guru in compiler construction, but I'd like to know.</div><div>
<br></div><div>Is this a logic by design that I easily get into a situation when querying interfaces is not "transitive".</div><div>I mean, having one of class interfaces I get another interface using which I cannot query the first one anymore.</div>
<div><br></div><div>Doesn't it defeat the purpose of interfaces? Seems like instead of staying away of class internals, I am forced to know the underlying details.</div><div><br></div><div>See example below. The same commenting again gives another results.</div>
<div>The last Print call just says that interface is not supported (btw, in Delphi also) if implemented using "implements". </div><div><div><br></div><div><div>type</div><div> IIntf1 = interface</div><div> ['{925B72C3-B47D-432A-AED8-544B3306055B}']</div>
<div> end;</div><div><br></div><div> IIntf2 = interface</div><div> ['{E5C9BAC0-CE6D-42A8-BC85-F0AA51360E83}']</div><div> procedure Print;</div><div> end;</div><div><br></div><div> { TClassBase }</div><div>
<br></div><div> TClassBase = class(TInterfacedObject{, IIntf2})</div><div> Int:Integer;</div><div><br></div><div> procedure Print;</div><div> end;</div><div><br></div><div> { TClass1 }</div><div><br></div><div> TClass1 = class(TClassBase, IIntf1)</div>
<div> public</div><div> constructor Create;</div><div> end;</div><div><br></div><div> { TClass2 }</div><div><br></div><div> TClass2 = class(TClassBase, IIntf1, IIntf2)</div><div> private</div><div> FIntf: IIntf1;</div>
<div> public</div><div> constructor Create;</div><div><br></div><div> procedure Print;</div><div> property Intf:IIntf1 read FIntf implements IIntf1; //COMMENT THIS LINE</div><div> end;</div><div><br></div><div>
{ TClassBase }</div><div><br></div><div>procedure TClassBase.Print;</div><div>begin</div><div> WriteLn('TClassBase.Print ', Int);</div><div>end;</div><div><br></div><div>constructor TClass2.Create;</div><div>var O:TClass1;</div>
<div>begin</div><div> Int:=3;</div><div><br></div><div> O:=TClass1.Create;</div><div> O.Int:=30;</div><div> FIntf:=O;</div><div>end;</div><div><br></div><div>{ TClass1 }</div><div><br></div><div>constructor TClass1.Create;</div>
<div>begin</div><div> Int:=1;</div><div>end;</div><div><br></div><div>procedure TClass2.Print;</div><div>begin</div><div> WriteLn('TClass2.Print ', Int);</div><div>end;</div><div><br></div><div>var C2:TClass2;</div>
<div> I1:IIntf1;</div><div> I2:IIntf2;</div><div>begin</div><div> try</div><div> C2:=TClass2.Create;</div><div><br></div><div> C2.Print;</div><div><br></div><div> I1:=C2 as IIntf1;</div><div><br></div><div>
I2:=C2 as IIntf2;</div><div> I2.Print;</div><div><br></div><div> I2:=I1 as IIntf2;</div><div> I2.Print;</div><div> except</div><div> on E:Exception do</div><div> WriteLn(E.Message);</div><div> end;</div>
<div><br></div><div> readln;</div><div>end.</div><br><div class="gmail_quote">On Wed, Nov 25, 2009 at 9:36 AM, Andrew Hall <span dir="ltr"><<a href="mailto:andrew.hall@shaw.ca">andrew.hall@shaw.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div style="word-wrap:break-word">This code is working correctly/logically - and the same as it does in Delphi...<div>
<br></div><div><div>Regards,</div><div><br></div><font color="#888888"><div>Andrew Hall.</div></font><div class="im"><div><br></div><div><div><div>_______________________________________________</div></div></div></div></div>
</div>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/mailman/listinfo/fpc-pascal</a><br></blockquote></div><br><br clear="all"><br>-- <br>Best regards,<br>Denis Golovan<br>
</div></div>