Hi,
In a large project I have a record definition, like:
type
PMyRec = ^TMyRec;
TMyRec = record
Enclosing: PMyRec;
Name: String;
constructor Create(const aName: String);
end;
var
Current: PMyRec; // gets a value later on
constructor TMyRec.Create(const aName: String);
begin
Enclosing := Current;
Name := aName;
Current := @Self;
end;
In the code I initialize a variable of type TMyRec as:
MyRec := TMyRec.Create('ABC');
However, this didn’t work and I got access violation errors.
When I changed the constructor into a normal procedure, like so:
procedure Init(const aName: String);
procedure TMyRec.Init(const aName: String);
begin
Enclosing := Current;
Name := aName;
Current := @Self;
end;
and used it like this:
This runs without any problems.
How can this be explained?
Delphi mode / trunk 4 weeks ago / MacOs Sonoma 14.5