As you know, Delphi provides many components that resemble standard controls but are data-aware. Data-aware controls (located on the Data Controls page of the Component palette) such as TDBEdit (DB version of the TEdit component) and TDBCheckBox (data-aware TCheckBox) automatically display the values associated with field components, beside being able to display data, data-aware controls can also send new and changed values to the database.
If you take a look at the Data Controls page you'll find more than 15 data-aware controls - all designed to automate the process of data editing and posting changes back to the database. If you take another look, you'll find something is missing: there's no control that can handle TDateTimeFields.
TadpDBDateTimePicker
TadpDBDateTimePicker is a data-aware descendant of the native TDateTimePicker control. Being a data-aware means that there are two new properties: DataSource - use it to connect to a TDataSource component; and a DataField - use it to connect the component to a date-time field. The TadpDBDateTimePicker control displays blank for a null field value; includes a ShowWeekNumbers property - when set to True week numbers are displayed in the drop-down calendar.
Warning ;)
The TadpDateTimePicker control is by no means perfect. It can be used to handle database fields that map to TDateField components, but it doesn't behave well with TTimeField fields (Kind property set to dtkTime).
Here's a thought from Peter Below (one of TeamB members): "The truth is that MS's DateTimePicker is badly designed fairly inflexible as a consequence. There is no method to get it to drop down or close up under program control other than faking keyboard input. There is no easy way to intercept the dropdown in a way that allows one to cancel it. To implement this one would indeed have to make a derived class and trap the users mouse and keyboard input to handle input events that would drop down the calendar. It may be easier to build your own picker from a TMaskEdit control, a TButton and a TMonthCalendar..."
Installing into a Component palette
First, download the component. The TadpDBDateTimePicker comes as a single unit file (.pas extension). You'll need to add the component into an existing package. Here's "How to Install Custom Component in Delphi (into Existing Package)"
Questions? Comments? Extensions? Exceptions?!
That's it. If you find this component practical and if you extend it by adding more properties, please send your source and make it available to other developers.
As always if there are any questions or comments please post them on the Delphi Programming Forum.
~ Zarko Gajic