Visibility of reintroduced constructor
Posted
by avenmore
on Stack Overflow
See other posts from Stack Overflow
or by avenmore
Published on 2010-05-17T10:52:45Z
Indexed on
2010/05/17
11:40 UTC
Read the original article
Hit count: 293
delphi
|constructor
I have reintroduced the form constructor in a base form, but if I override the original constructor in a descendant form, the reintroduced constructor is no longer visible.
type
TfrmA = class(TForm)
private
FWndParent: HWnd;
public
constructor Create(AOwner: TComponent; const AWndParent: Hwnd); reintroduce; overload; virtual;
end;
constructor TfrmA.Create(AOwner: TComponent; const AWndParent: Hwnd);
begin
FWndParent := AWndParent;
inherited Create(AOwner);
end;
type
TfrmB = class(TfrmA)
private
public
end;
type
TfrmC = class(TfrmB)
private
public
constructor Create(AOwner: TComponent); override;
end;
constructor TfrmC.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
When creating:
frmA := TfrmA.Create(nil, 0);
frmB := TfrmB.Create(nil, 0);
frmC := TfrmC.Create(nil, 0); // Compiler error
My work-around is to override the reintroduced constructor or to declare the original constructor overloaded, but I'd like to understand the reason for this behavior.
type
TfrmA = class(TForm)
private
FWndParent: HWnd;
public
constructor Create(AOwner: TComponent); overload; override;
constructor Create(AOwner: TComponent; const AWndParent: Hwnd); reintroduce; overload; virtual;
end;
type
TfrmC = class(TfrmB)
private
public
constructor Create(AOwner: TComponent; const AWndParent: Hwnd); override;
end;
© Stack Overflow or respective owner