I\'m trying to create a child class of TForm with
There's a really easy way to avoid this. Give your new constructor a different name. Unlike some other popular languages, Delphi has named constructors; you don't have to call them Create. You could call your new one CreateWithDataset and not interfere with the virtual Create constructor at all.
TfrmEndoscopistSearch = class(TForm)
/// original constructor kept for compatibility
constructor Create(AOwner: TComponent); override;
/// additional constructor allows for a caller-defined base data set
constructor CreateWithDataset(AOwner: TComponent; ADataSet: TDataSet; ACaption: string = '');
end;
In fact, unless you're instantiating this class polymorphically, you don't even need the original constructor. You could declare your new one like this:
TfrmEndoscopistSearch = class(TForm)
/// additional constructor allows for a caller-defined base data set
constructor Create(AOwner: TComponent; ADataSet: TDataSet; ACaption: string = ''); reintroduce;
end;
Attempting to call the one-argument constructor directly on TfrmEndoscopistSearch would yield a compilation error.
(Creating it polymorphically would generally involve using Application.CreateForm:
Application.CreateForm(TfrmEndoscopistSearch, frmEndoscopistSearch);
That always calls the one-argument virtual constructor introduced in TComponent. Unless it's your main form, you don't need to do that. I've written about my feelings on Application.CreateForm before.)
constructor Create(AOwner:Tcomponent;str:string);overload;
...
constructor TfrmEndoscopistSearch.Create(AOwner: Tcomponent; str: string);
begin
inherited Create(AOwner);
showmessage(str);
end;
This should do the trick
Try adding reintroduce
before the second overload
, like this:
TfrmEndoscopistSearch = class(TForm)
public
/// original constructor kept for compatibility
constructor Create(AOwner : TComponent); overload; override;
/// additional constructor allows for a caller-defined base data set
constructor Create(AOwner : TComponent; ADataSet : TDataSet; ACaption : string = ''); reintroduce; overload;
end;
This compiles in Turbo Delphi. I needed the public
to make it compile because overloading of published
methods is restricted.