Inheritance and the constructor
First, you'll define your new class, inheriting from TQTXWidget or another suitable ancestor (like TQTXContentBox if you need alignment features).
Your constructor must follow the standard pattern. It takes an AOwner and a CB (callback) of its own type. Inside, you must call the inherited Create and pass an anonymous procedure. This pattern ensures the widget's lifecycle is correctly managed.
type
// Forward declare your constructor type
TMyWidgetConstructor = procedure (Widget: TMyWidget);
TMyWidget = class(TQTXWidget)
public
// Reintroduce the constructor with your specific callback type
constructor Create(AOwner: TQTXComponent; CB: TMyWidgetConstructor); reintroduce; virtual;
end;
constructor TMyWidget.Create(AOwner: TQTXComponent; CB: TMyWidgetConstructor);
begin
// Call the inherited constructor
inherited Create(AOwner, procedure (Widget: TQTXWidget)
begin
// --- Your setup code goes here ---
// Finally, call the user's callback (if they provided one)
if assigned(CB) then
CB(self);
end);
end;