I would like to create a TSpeedButton
descendant named TMyDropDownButton
with a TButtonGroup
field. When I push the TSpeedButton
, the TButtonGroup
should appear in the right place (due to some other property values venished here).
This TButtonGroup
property should be read-only (the program creates it in the Create()
constructor before the inherited
constructor is called), and should be published (save the design-time values into the DFM).
But, when I place a TMyDropDownButton
instance onto a form, the TButtonGroup
property is unset by default. I can link a dropped TButtonGroup
when I add a write accessor to the TButtonGroup
property, but I dont want this. I want the
TButtonGroupproperty to be linked to the
TButtonGroupinstance created in the constructor, and preset by the
Loaded()` method.
How can I do that?
Here is my attempt:
unit MyDropDownButton;
interface
uses
System.Classes
, Vcl.ButtonGroup
, Vcl.Buttons
;
type
TMyDropDownButton = class ( TSpeedButton )
private
// Fields
fButtonGroup : TButtonGroup;
protected
procedure Loaded; override;
public
constructor Create( owner_ : TComponent );
destructor Destroy; override;
published
property buttonGroup : TButtonGroup read fButtonGroup;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('myDropDownButton', [TMyDropDownButton]);
end;
procedure TMyDropDownButton.Loaded;
begin
inherited Loaded;
// I need some settings here due to venished props inrelevant for the question
end;
constructor TMyDropDownButton.Create( owner_ : TComponent );
begin
fButtonGroup := TButtonGroup.Create( self );
inherited Create( owner_ );
fButtonGroup.Parent := parent;
end;
destructor TMyDropDownButton.Destroy;
begin
// FreeAndNIL( fButtonGroup );
inherited Destroy;
end;
end.