TDatePick
Source: source/classes/tdtpicke.prg
Inherits from: TControl
TDatePick wraps the Windows date and time picker common control (SysDateTimePick32).
It provides a drop-down calendar for date selection and supports both date-only and date-time
modes with configurable display formats, range restrictions, and multi-select capability.
Command Syntax
@ nRow, nCol DTPICKER oDtp VAR dDate SIZE nW, nH PIXEL OF oWnd ;
PICTURE cFmt ON CHANGE bBlock
Key DATA Members
| DATA | Type | Description |
|---|---|---|
lDateTime | Logical | Enable date-time mode (T value) instead of date-only |
cPicture | Character | Display format picture (e.g., "dd/mm/yyyy") |
lMultiSelect | Logical | Enable multi-date selection in the drop-down calendar |
lNoToday | Logical | Hide the "Today" button at the bottom of the drop-down |
nMaxSelDays | Numeric | Maximum number of selectable days in multi-select mode |
lWeekNumbers | Logical | Show week numbers in the drop-down calendar |
lNoTodayCircle | Logical | Hide the circle around today's date in the drop-down |
lNoTrailingDates | Logical | Hide dates from previous/next months |
Methods
| Method | Description |
|---|---|
New( nRow, nCol, bSetGet, oWnd, nWidth, nHeight, bValid, nClrFore, nClrBack, oFont, lDesign, oCursor, lPixel, cMsg, lUpdate, bWhen, bChange, nHelpId, cPic, nStyle ) | Create a new TDatePick control |
ReDefine( nId, bSetGet, oWnd, nHelpId, nClrFore, nClrBack, oFont, oCursor, cMsg, lUpdate, bWhen, bValid, bChanged, cPic ) | Redefine from dialog resource |
SetDate( dDate, lEmpty ) | Set the picker to a specific date (optionally allow empty) |
GetDate() | Retrieve the currently selected date or datetime value |
SetRange( dFrom, dUpto ) | Restrict the selectable date range |
GetRange() | Retrieve the current minimum and maximum date range |
Open() | Programmatically open the drop-down calendar |
cText( uVal ) | Get or set the formatted text value (SETGET) |
Refresh() | Refresh the control from the bound variable |
Change() | Execute the bChange code block |
Examples
Date Picker with Format
#include "FiveWin.ch"
function Main()
local oWnd, oDtp, dDate := Date()
DEFINE WINDOW oWnd TITLE "Date Picker Demo" SIZE 350, 200
@ 40, 30 DTPICKER oDtp VAR dDate SIZE 120, 22 PIXEL OF oWnd ;
PICTURE "dd/mm/yyyy" ;
ON CHANGE MsgInfo( DToC( dDate ), "Date Changed" )
oDtp:SetRange( Date() - 365, Date() + 365 )
@ 100, 30 BUTTON "&Get Date" SIZE 80, 25 PIXEL OF oWnd ;
ACTION MsgInfo( DToC( oDtp:GetDate() ) )
ACTIVATE WINDOW oWnd CENTERED
return nil
Date-Time Picker
#include "FiveWin.ch"
function Main()
local oWnd, oDtp, tDateTime := DateTime()
DEFINE WINDOW oWnd TITLE "DateTime Picker" SIZE 350, 200
@ 40, 30 DTPICKER oDtp VAR tDateTime SIZE 180, 22 PIXEL OF oWnd ;
PICTURE "dd/mm/yyyy HH:MM:SS"
@ 100, 30 BUTTON "&Show" SIZE 80, 25 PIXEL OF oWnd ;
ACTION MsgInfo( DToC( oDtp:GetDate() ), "Selected" )
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- When the bound variable is of type
T(DateTime), the control automatically switches to date-time mode (lDateTime := .T.) and displays the time portion. - The
PICTUREclause accepts standard date/time format strings:dd/mm/yyyy,mm/dd/yyyy,yyyy-mm-dd, and appendingHH:MM:SSfor time display. - Use
SetRange()to restrict the date range the user can select. The drop-down calendar will gray out dates outside this range. - The
Open()method programmatically opens the drop-down MonthCal calendar, which is useful for validation or re-selection flows. - Multi-select options (
lMultiSelect,lWeekNumbers) apply to the drop-down calendar and are set before the control is created.