This is a known issue in the implementation of the Delphi date picker control (fixed in Delphi 2009, as @Remy pointed out in his comment). To request the Date Picker, either DTM_GETSYSTEMTIME or DateTime_GetSystemtime , which internally sends this message, should be used. If the message (or macro) returns GDT_VALID and GDT_VALID used (in Delphi, when the ShowCheckbox property is True), this indicates that the control is checked and this control contains a valid time.
Here is an example of using the specified macro to determine the state of a flag:
uses CommCtrl; procedure TForm1.DateTimePicker1Change(Sender: TObject); var SysTime: SYSTEMTIME; begin if DateTime_GetSystemTime(DateTimePicker1.Handle, @SysTime) = GDT_VALID then ShowMessage('Check box is checked!') else ShowMessage('Check box is not checked!'); end;
So, you can make a helper function like this to bypass the incorrect Delphi implementation:
uses CommCtrl; function IsDateTimePickerChecked(ADateTimePicker: TDateTimePicker): Boolean; var SysTime: SYSTEMTIME; begin Result := DateTime_GetSystemTime(ADateTimePicker.Handle, @SysTime) = GDT_VALID; end; procedure TMyForm.ButtonOneClick(Sender: TObject); begin if IsDateTimePickerChecked(DateTimePicker1) then ShowMessage('Check box is checked!') else ShowMessage('Check box is not checked!'); end;
TLama source share