[fpc-devel] Interface scope incompatibility with Delphi

Marc Weustink marc.weustink at cuperus.nl
Fri Nov 12 10:33:27 CET 2010


Dimitri Smits wrote:
> ok, answering my own mail after a small test below
>
> ----- "Dimitri Smits"<smitco at telenet.be>  schreef:
>
>> what I DON'T do is use it like in your example, Graeme. I always
>> assign the result to a local variable, which goes out of scope in an
>> implicit finally block at method-exit. Haven't tried if this does
>> (not) work in fpc though.
>>
>
> tested with following program and 2.4.0 (can someone verify on trunk)
>
> it gives somewhat the desired result, but not completely. This IS a bug, I believe.
>
> the expected behaviour is the next output:
>    Entering: DoSomething 1
>    Entering: DoSomething 2
>    random message 1
>    random message 2
>    Exiting: DoSomething 2
>    Exiting: DoSomething 1
>
> but I got this output:
>    Entering: DoSomething 1
>    Entering: DoSomething 2
>    random message 1
>    random message 2
>    Exiting: DoSomething 1
>    Exiting: DoSomething 2
>
> it seems that the stackvariables are NOT unloaded in the correct order (ie: reverse order of declaration).
> It shouldn't matter in what order you fill them, but in the order they are declared. (like good practice in constructor vs destructor, but then in stack variables setup/cleanup)

IMO not.
Why should the order of declaration matter on how your code works ? 
It's just an declaration.
If your code requires a specific unload order, code it that way by 
setting the variables to nil in the order you need. That is the only way 
you can make sure that interfaces will be unloaded in the correct order.
In Delphi I had a issue when working with DirectSound interfaces. The 
order how interfaces are unloaded was important, the Delphi default way 
lead to a crash. Explicitly nilling the variables in the correct order 
solved this.

Marc




More information about the fpc-devel mailing list