I have this application that reuses a sort of idiom in a number of places. There\'s a TPanel, and on it are some labels and buttons. The purpose is to allow the user to sele
It's reasonable, yes.
To create such a component, just derive a new class from for instance TCustomPanel, and add the sub-components as fields within the class.
Like this:
TMyDatePicker = class(TCustomPanel)
protected
FChooseButton: TButton;
FClearButton: TButton;
public
constructor Create(Owner: TComponent); override;
end;
constructor TMyDatePicker.Create(Owner: TComponent)
begin
// Inherited
Inherited;
// Create Choose Button
FChooseButton := TButton.Create(Self);
FChooseButton.Parent := Self;
FChooseButton.Align := alRight;
FChooseButton.Caption := 'Choose';
// Create Clear Button
FClearButton := TButton.Create(Self);
FClearButton.Parent := Self;
FClearButton.Align := alRight;
FClearButton.Caption := 'Clear';
end;
To add event handers, just add new protected procedures to your class.
For instance:
procedure TMyDatePicker.HandleChooseButtonClick(Sender: TObject)
begin
// Do whatever you want to do when the choose button is clicked
end;
Then connect the event handler to the OnClick event of the choose button (this should be done within the Create method of the class):
FChooseButton.OnClick := HandleChooseButtonClick;
There's a bit more to it than this, of course, such as fine tuning the alignments of the buttons and adding icons. Also you'll need to create your own events, such as OnDateSelected or OnDateModified.
But, apart from that, I think the above example should at least get you going. :)