Delphi XE8. FMX. Why is different release order of CLASS VAR on Android platform?

  

Tested with Delphi XE7 Update 1 and Delphi XE8

Create order on Windows OS (7 SP1 x64), MACOSX (10.10.3) and Android (5.0.2):

“class constructor TGlobalClass.Create;” -> “constructor TfmMain.Create;” -> “procedure TfmMain.FormCreate(Sender: TObject);”

Release order on Windows OS and MACOSX:

“TfmMain.FormDestroy” -> “destructor TfmMain.Destroy” -> “class destructor TGlobalClass.Destroy;”

Release order on Android:

“class destructor TGlobalClass.Destroy;” -> “TfmMain.FormDestroy” -> “destructor TfmMain.Destroy”

Question is: why on Android platform CLASS VAR releasing before main form?

Sample of code:

unit uClassVar;

interface

type
TGlobalClass = class
class var F1: Integer;

class constructor Create;
class destructor Destroy;
end;

implementation

{ TX }

class constructor TGlobalClass.Create;
begin
{ Breakpoint there }
F1 := 100;
end;

class destructor TGlobalClass.Destroy;
begin
{ Breakpoint there }
F1 := 200;
end;

end.

Main unit:

unit ufmMain;

interface

uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics;

type
TfmMain = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;

var
fmMain: TfmMain;
z: Integer;

implementation

uses
uClassVar;

{$R *.fmx}

constructor TfmMain.Create;
begin
{ Breakpoint there }
inherited;
end;

destructor TfmMain.Destroy;
begin
{ Breakpoint there }
inherited;
end;

procedure TfmMain.FormCreate(Sender: TObject);
begin
{ Breakpoint there }
TGlobalClass.F1 := -99999;
end;

procedure TfmMain.FormDestroy(Sender: TObject);
begin
{ Breakpoint there }
z := 200;
end;

end.

Project file:

program ClassVar;

uses
System.StartUpCopy,
FMX.Forms,
ufmMain in ‘ufmMain.pas’ {fmMain},
uClassVar in ‘uClassVar.pas’;

{$R *.res}

begin
Application.Initialize;
Application.CreateForm(TfmMain, fmMain);
Application.Run;
end.

Comments are closed.