delphi - Is it wise to create composite controls? -
i have application reuses sort of idiom in number of places. there's tpanel, , on labels , buttons. purpose allow user select date range.
the "&dates" caption 1 label, , "all dates" part second one. when user clicks "choose" button form pops presenting user pair of date/time controls , ok/cancel buttons. if user hits ok after selecting dates, 2nd label changes "from mm/dd/yyyy mm/dd/yyyy".
is plausible create component packages these controls? have been looking @ various resources component writers , don't seem pointed @ problems thinking about, such handling onclick events buttons. if reasonable thing attempt, i'd appreciate pointers descriptions of how make such "composite control."
it's reasonable, yes.
to create such component, derive new class instance tcustompanel, , add sub-components fields within 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, add new protected procedures class.
for instance:
procedure tmydatepicker.handlechoosebuttonclick(sender: tobject) begin // whatever want when choose button clicked end; then connect event handler onclick event of choose button (this should done within create method of class):
fchoosebutton.onclick := handlechoosebuttonclick; there's bit more this, of course, such fine tuning alignments of buttons , adding icons. you'll need create own events, such ondateselected or ondatemodified.
but, apart that, think above example should @ least going. :)
Comments
Post a Comment