How can I enable the datetimepicker control to display both dates and times, and modify and save them?
My solution:
First, set the format attribute of the control to mm DD, yyyy, mm, mm, SS, and kind to dtktime.
Where you want to save the value in the control, such as in the change event (of course this is not a good place, it is enough to take only one time, this is just for you to view the effect), write the followingCode:
Procedure tfrom_sms.datetimepicker2change (Sender: tobject );
VaR
SS: string;
PP: pchar;
Begin
// Time1: = formatdatetime ('Mm minute SS second At HH on mm dd, yyyy ', datetimepicker2.datetime );
// The datetime attribute of the control cannot be used, because it only records changes in the part specified by the kind attribute (dtkdate or dtktime), but does not record changes in the other part.
PP: = stralloc (20); // allocate memory for pchar
Datetimepicker2.gettextbuf (PP, 20 );
SS: = pp;
Showmessage (SS );
Strdispose (PP); // For pchar to release memory, which must be available; otherwise, an error is returned.
End;
Note that the current bug is:
If the date is modified first, the date is automatically restored when the time is modified.
Therefore, you can only modify the time before modifying the date.
I wonder if you can solve this problem.
the reason why you don't need the maskedit (or simply edit) control is to use some advantages of datetimepicker:
1. valid input verification (year, month, day, hour, minute, and second have boundaries, and also involve issues such as leap year and month)
2. up and down arrow. you can try it. Although it is usually time-specific, it also has an effect on the date part in the example I changed. of course, this is secondary and dispensable. it is mainly about 1st points.