<div dir="ltr"><div><div><div><div>Yes, that is what i mean with "topmost" type: if you look at the inheritance as a tree, TInterfacedObject is the topmost (or root, if you think of it as an upside-down tree) of the type hierarchy. In this code<br>
<br></div> type<br></div> IBlah = interface ... end;<br></div> TBlah = class(TInterfacedObject, IBlah) ... end;<br><br></div>TBlah is an IBlah, so i'd expect it to behave like IBlah.<br><div><br></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Thu, Mar 21, 2013 at 2:10 PM, Sven Barth <span dir="ltr"><<a href="mailto:pascaldragon@googlemail.com" target="_blank">pascaldragon@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Am <a href="tel:21.03.2013%2013" value="+12103201313" target="_blank">21.03.2013 13</a>:55, schrieb Kostas Michalopoulos:<div class="im"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I haven't used (COM) interfaces so far since i didn't found any use for them in my code, but i didn't knew about their reference counting properties. That could save a lot of headaches i have with my 3D world editor's lightmap generation (currently there is some wrong memory deallocation somewhere that crashes the editor in partial lightmap recalculations). I plan to redesign it at some point soon and i was thinking how to handle this. Since there is native refcounting support in FPC it makes things much easier.<br>
<br>
However i did a small test and i noticed something that, to me (as someone who hasn't used COM at all) looks a bit weird:<br>
<br>
If i do a declaration like<br>
<br>
type<br>
IResource = interface end;<br>
TResource = class(TInterfacedObject, IResource) ... stuff ... end;<br>
<br>
TSomething = class<br>
...<br>
Resources: array of TResource;<br>
...<br>
end;<br>
<br>
then reference counting doesn't work. However if i change Resources to<br>
<br>
Resources: array of IResource;<br>
<br>
then it works. It seems that the compiler checks only the "topmost" type and doesn't check if TResource implements the IResource and thus doesn't do any reference counting. Is this a bug or it is supposed to work this way?<br>
<br>
If the latter, is there a way to make the compiler do reference counting on a variable that has a class type which implements an interface instead of a type that is an interface itself? Or is there any other form of reference counted classes?<br>
<br>
</blockquote></div>
The compiler does not check for any topmost type. It uses reference counting only for variables that are of an interface type not for a class type.<br>
<br>
E.g.:<br>
<br>
=== example begin ===<br>
<br>
var<br>
i: IInterface;<br>
t: TInterfacedObject;<br>
begin<br>
t := TInterfacedObject.Create;<br>
t.Free;<br>
// no reference counting is done here<br>
<br>
i := TInterfacedObject.Create;<br>
i := Nil;<br>
// reference counting is done here<br>
end;<br>
<br>
=== example end ===<br>
<br>
Regards,<br>
Sven<div class="HOEnZb"><div class="h5"><br>
<br>
--<br>
______________________________<u></u>_________________<br>
Lazarus mailing list<br>
<a href="mailto:Lazarus@lists.lazarus.freepascal.org" target="_blank">Lazarus@lists.lazarus.<u></u>freepascal.org</a><br>
<a href="http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus" target="_blank">http://lists.lazarus.<u></u>freepascal.org/mailman/<u></u>listinfo/lazarus</a><br>
</div></div></blockquote></div><br></div>