Could you show the EXACT code and EXACT error message.
Because I suspect this code doesn't run in Delphi either.
Well, it could work, because the constructor, when called on an instance, is just a function that returns self:
TTest = class
constructor Create;
end;
constructor TTest.Create;
begin
end;
var
t1,t2: TTest;
begin
t1:=TTest.Create;
t2:=t1.Create;
WriteLn(t1=t2); // TRUE
end.
One thing with FPC is, that the constructor does not return the type that it is called on, but the type that defines it:
type
TBase=class
constructor Create;
end;
TChild=class(TBase);
constructor TBase.Create;
begin
end;
var
t1,t2: TChild;
begin
t1:=TChild.Create;
t2:=t1.Create; // Error TBase expected, TChild got
WriteLn(t1=t2);
end.
A behavior that I started to suspect to be a bug in FPC some time ago. If Delphi does not have this "bug", but instead t1.Create returns the type of t1 instead of the parent type where Create was defined on, then this example would compile.
In this case basically the following:
Contacts:= FrmContacts.Create(Self);
FrmContacts.Show;
Would compile just fine, and it would result in the first the constructor code being re-run (which re-initializes the form, probably introducing some memory leaks), and then contacts being assigned to be the same object as FrmContacts. Finally FrmContacts.Show would just show that form.
But I don't have a Delphi version installed to test if Delphi behaves that way (and thereby if the behavior of FPC is indeed a bug)