Wrong BeforeDestruction triggering
Original Reporter info from Mantis: silvioprog
-
Reporter name: silvioprog
Original Reporter info from Mantis: silvioprog
- Reporter name: silvioprog
Description:
Hello,
The following example makes different results between Free Pascal and Delphi:
=== begin code ===
program project1;
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$IFDEF MSWINDOWS}
{$APPTYPE CONSOLE}
{$ENDIF}
uses SysUtils;
type
TSomeClass = class
public
procedure LoadSomething;
end;
TA = class
private
FSomeObject: TSomeClass;
public
constructor Create; virtual;
destructor Destroy; override;
procedure AfterConstruction; override;
procedure BeforeDestruction; override;
property SomeObject: TSomeClass read FSomeObject;
end;
procedure TSomeClass.LoadSomething;
begin
raise Exception.Create('An exception loading something');
end;
constructor TA.Create;
begin
WriteLn(1);
inherited Create;
end;
destructor TA.Destroy;
begin
WriteLn(2);
inherited Destroy;
end;
procedure TA.AfterConstruction;
begin
WriteLn(3);
FSomeObject := TSomeClass.Create;
FSomeObject.LoadSomething;
end;
procedure TA.BeforeDestruction;
begin
WriteLn(4);
FSomeObject.Free;
end;
var
VA: TA;
begin
VA := TA.Create;
try
finally
VA.Free;
end;
end.
=== end code ===
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:
$ ./project1
1
3
2
An unhandled exception occurred at $00000000004001CD:
Exception: An exception loading something<br/>
$00000000004001CD LOADSOMETHING, line 30 of project1.lpr
$000000000040045A AFTERCONSTRUCTION, line 50 of project1.lpr
$00000000004002CC CREATE, line 38 of project1.lpr
$00000000004004FA main, line 62 of project1.lpr
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):
Win32\Debug>Project1.exe
1
3
4
2
^C
(I needed to kill the app by Ctrl+C within terminal)
the critical exception was the known:
[Main Instruction]
Project1.exe has stopped working
[Content]
Windows is checking for a solution to the problem...
Additional information:
Related topic with more details: http://lists.freepascal.org/pipermail/fpc-pascal/2016-September/048787.html .
Mantis conversion info:
- Mantis ID: 30570
- Version: 3.1.1
- Fixed in version: 3.1.1
- Fixed in revision: 34453 (#1e506ce1)