Hi all<div><br></div><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><div>
<br>======================================</div><div>program project1;</div><div><br></div><div>{$mode objfpc}{$H+}</div><div><br></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)</div><div> private</div><div> FIntf: IIntf1;</div>
<div> public</div><div> constructor Create;</div><div><br></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>var C2:TClass2;</div><div> I1:IIntf1;</div><div> I2:IIntf2;</div><div>begin</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>end.</div><div>======================================</div>
</div><div><br>-- <br>Best regards,<br>Denis Golovan<br>
</div>