Sorry for re-opening this. While PascalDragon has fixed the initial issue and this has been merged to FPC3.2.3., it only works with TSys as a Class. When making TSys an oldstyle object, the bug is back.
In the code below, LocalGEN is initialised upon program start
before Sys has been initialised. That should not be a problem as both are static. Indeed after initalisation of Sys, the address of Sys.LocalGEN is the same as reported during LocalGen's own initalisation. But, Sys.LocalGen.state still returns 0 instead of 55.
Tested with FPC 3.2.3 from 2023/03/05, i386-win32.
Can someone please test and confirm, then I'll file a bug report.
{$APPTYPE CONSOLE}
{$IFDEF FPC}
{$MODE OBJFPC}
{$MODESWITCH ADVANCEDRECORDS}
{$ENDIF}
type TGen= record
fstate: longword;
class operator Initialize (var R: TGen);
property state: longword read fstate;
end;
TSys = object //issue is solved for TSys as Class but not as object!
LocalGen: TGen;
constructor Init;
end;
(********* TGen *****************************************)
class operator TGen.Initialize (var R: TGen);
begin
R.fstate := 55;
writeln ('TGEN initialized ! My address is ',ptruint (@R));
end;
(********* TSYS *******************************************)
constructor TSys.Init;
var i: integer;
begin
inherited;
writeln ('ok');
// Initialize (LocalGEN); //this would solve it but then LocalGen.Init is called twice
end;
var Sys: TSys;
begin
writeln ('About initialising Sys');
Sys.init;
writeln ('The address of Sys.LocalGEN is ',ptruint (@Sys.LocalGEN));
writeln ('Accessing Sys.LocalGEN.state results in : ', Sys.LocalGEN.state);
writeln;
end.