[fpc-devel] Interface scope incompatibility with Delphi
Michael Van Canneyt
michael at freepascal.org
Wed Nov 10 10:30:52 CET 2010
On Wed, 10 Nov 2010, Graeme Geldenhuys wrote:
> Attached is a simple console application that outputs a hierarchy of log
> information. Under Delphi 7 we used to use a TInterfacedObject descendant
> to track the call stack. This same trick was very handy for changing and
> restoring the mouse cursor too.
> When you create an instance it logs entry information, and increased the
> indentation level. When that interface instance went out of scope in
> decreased the indentation level and logs exit information.
> Unfortunately this doesn't have the same affect under FPC (tested with
> Windows and Linux).
> The problem is that under FPC, the Interface instances immediately goes out
> of scope. It seems Delphi held on to that instance even though you did not
> store it in a variable. Once the current procedure/method is complete, then
> only the Interface instance went out of scope.
It depends. You're not supposed to make assumptions on when an interface
goes out of scope. If you search the archives, you'll find multiple threads
about this, where Jonas (with his legendary patience) explained to people
why this assumption is false, and that indeed FPC is not compatible to
Delphi in this regard, and that this will not be changed.
More information about the fpc-devel