<div dir="ltr"><div>Hello,</div><div><br></div><div>My question at title seems stupid, but the reason why I've get this doubt is just because it get different results between Free Pascal and Delphi in the following example:</div><div><br></div><div>=== begin code ===</div><div><br></div><div><font face="monospace, monospace" size="1">program project1;</font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">{$IFDEF FPC}</font></div><div><font face="monospace, monospace" size="1"> {$MODE DELPHI}</font></div><div><font face="monospace, monospace" size="1">{$ENDIF}</font></div><div><font face="monospace, monospace" size="1">{$IFDEF MSWINDOWS}</font></div><div><font face="monospace, monospace" size="1"> {$APPTYPE CONSOLE}</font></div><div><font face="monospace, monospace" size="1">{$ENDIF}</font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">uses SysUtils;</font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">type</font></div><div><font face="monospace, monospace" size="1"> TSomeClass = class</font></div><div><font face="monospace, monospace" size="1"> public</font></div><div><font face="monospace, monospace" size="1"> procedure LoadSomething;</font></div><div><font face="monospace, monospace" size="1"> end;</font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1"> TA = class</font></div><div><font face="monospace, monospace" size="1"> private</font></div><div><font face="monospace, monospace" size="1"> FSomeObject: TSomeClass;</font></div><div><font face="monospace, monospace" size="1"> public</font></div><div><font face="monospace, monospace" size="1"> constructor Create; virtual;</font></div><div><font face="monospace, monospace" size="1"> destructor Destroy; override;</font></div><div><font face="monospace, monospace" size="1"> procedure AfterConstruction; override;</font></div><div><font face="monospace, monospace" size="1"> procedure BeforeDestruction; override;</font></div><div><font face="monospace, monospace" size="1"> property SomeObject: TSomeClass read FSomeObject;</font></div><div><font face="monospace, monospace" size="1"> end;</font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">procedure TSomeClass.LoadSomething;</font></div><div><font face="monospace, monospace" size="1">begin</font></div><div><font face="monospace, monospace" size="1"> raise Exception.Create('An exception loading something');</font></div><div><font face="monospace, monospace" size="1">end;</font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">constructor TA.Create;</font></div><div><font face="monospace, monospace" size="1">begin</font></div><div><font face="monospace, monospace" size="1"> WriteLn(1);</font></div><div><font face="monospace, monospace" size="1"> inherited Create;</font></div><div><font face="monospace, monospace" size="1">end;</font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">destructor TA.Destroy;</font></div><div><font face="monospace, monospace" size="1">begin</font></div><div><font face="monospace, monospace" size="1"> WriteLn(2);</font></div><div><font face="monospace, monospace" size="1"> inherited Destroy;</font></div><div><font face="monospace, monospace" size="1">end;</font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">procedure TA.AfterConstruction;</font></div><div><font face="monospace, monospace" size="1">begin</font></div><div><font face="monospace, monospace" size="1"> WriteLn(3);</font></div><div><font face="monospace, monospace" size="1"> FSomeObject := TSomeClass.Create;</font></div><div><font face="monospace, monospace" size="1"> FSomeObject.LoadSomething;</font></div><div><font face="monospace, monospace" size="1">end;</font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">procedure TA.BeforeDestruction;</font></div><div><font face="monospace, monospace" size="1">begin</font></div><div><font face="monospace, monospace" size="1"> WriteLn(4);</font></div><div><font face="monospace, monospace" size="1"> FSomeObject.Free;</font></div><div><font face="monospace, monospace" size="1">end;</font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">var</font></div><div><font face="monospace, monospace" size="1"> VA: TA;</font></div><div><font face="monospace, monospace" size="1">begin</font></div><div><font face="monospace, monospace" size="1"> VA := TA.Create;</font></div><div><font face="monospace, monospace" size="1"> try</font></div><div><font face="monospace, monospace" size="1"> finally</font></div><div><font face="monospace, monospace" size="1"> VA.Free;</font></div><div><font face="monospace, monospace" size="1"> end;</font></div><div><font face="monospace, monospace" size="1">end.</font></div><div><br></div><div>=== end code ===</div><div><br></div><div>I've compiled it in Free Pascal from trunk (version 3.1.1 [2016/08/26] for x86_64) installed on a Xubuntu 16.04 64 bits, and got the following log:</div><div><br></div><div><font face="monospace, monospace" size="1">$ ./project1</font></div><div><font face="monospace, monospace" size="1">1</font></div><div><font face="monospace, monospace" size="1">3</font></div><div><font face="monospace, monospace" size="1">2</font></div><div><font face="monospace, monospace" size="1">An unhandled exception occurred at $00000000004001CD:</font></div><div><font face="monospace, monospace" size="1">Exception: An exception loading something</font></div><div><font face="monospace, monospace" size="1"> $00000000004001CD LOADSOMETHING, line 30 of project1.lpr</font></div><div><font face="monospace, monospace" size="1"> $000000000040045A AFTERCONSTRUCTION, line 50 of project1.lpr</font></div><div><font face="monospace, monospace" size="1"> $00000000004002CC CREATE, line 38 of project1.lpr</font></div><div><font face="monospace, monospace" size="1"> $00000000004004FA main, line 62 of project1.lpr</font></div><div><br></div><div>and I've compiled the same code in an original version of Delphi Pro (version 10.1 Berlin 24.0.22858.6822), on a Windows 10 64 bits, and I got the log below and a critical exception (notice the result numbers, they are different from similar test compiled in Free Pascal):</div><div><br></div><div><font face="monospace, monospace" size="1">Win32\Debug>Project1.exe</font></div><div><font face="monospace, monospace" size="1">1</font></div><div><font face="monospace, monospace" size="1">3</font></div><div><font face="monospace, monospace" size="1">4</font></div><div><font face="monospace, monospace" size="1">2</font></div><div><font face="monospace, monospace" size="1">^C</font></div><div><br></div><div>(I need to kill the app by Ctrl+C within terminal)</div><div><br></div><div>the critical exception was the known:</div><div><br></div><div><font face="monospace, monospace" size="1">[Main Instruction]</font></div><div><font face="monospace, monospace" size="1">Project1.exe has stopped working</font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">[Content]</font></div><div><font face="monospace, monospace" size="1">Windows is checking for a solution to the problem...</font></div><div><br></div><div>So, is it a bug? If so, in which compiler?! Even after reading some documents about BeforeDestruction I still have doubt about which is the correct triggering of this method, and I would be glad if someone could help me to solve it.</div><div><br></div><div>--</div><div>Silvio Clécio</div>
</div>