I have the following superclass:
unit DlgDefaultForm;
type
TDefaultFormDlg = class(TForm)
published
constructor Create(AOwner: TComponent); reintroduce; virtual;
end;
FormCreateFunc=function(AOwner: TComponent):TDefaultFormDlg;
which is descended by a bunch of forms as follows:
unit Form1
type
TForm1 = class(TDefaultFormDlg)
published
constructor Create(AOwner: TComponent); override;
end;
and created as follows:
unit MainForm;
procedure ShowForm(FormCreate:FormCreateFunc);
begin
(do some stuff)
FormCreate(ScrollBox1);
end;
When I run
ShowForm(@TForm1.Create);
two things happen:
-
When I step into TForm1.Create, AOwner=nil, even when it didn’t in ShowForm.
-
I get an EAbstractError at the following line:
unit Forms; (...) constructor TCustomForm.Create(AOwner: TComponent); begin (...) InitializeNewForm; //EAbstractError (...) end;
What am I doing wrong?
EDIT: This of course isn’t my exact code.
You’re not using virtual constructors correctly. Try it like this:
As an aside I do not think you need to reintroduce the constructor in the code you listed.