DelphiVCL.DateTimePicker or TDateTimePicker displays a list box for entering dates or times.
TDateTimePicker is a visual component designed specifically for entering dates or times. It resembles a list box or combo box, except that the drop-down list is replaced with a calendar illustration; users can select a date from the calendar. Dates or times can also be selected by scrolling with Up and Down arrows and by typing.
Browse all the properties, methods, and built-in properties of the DelphiVCL.DateTimePicker using dir() command:
1 2 3 |
import DelphiVCL dir(DelphiVCL.DateTimePicker) |
See the responses in our Windows command prompt:
Here is the working example of the implementation of DelphiVCL.DateTimePicker to create a datetime picker:
1 2 3 4 |
# Datetime picker creation dtpDateofIssue = CreateComponent('TDateTimePicker',pgOne) dtpDateofIssue.SetProps(Parent=pgOne) dtpDateofIssue.SetBounds(175,150,125,30) |
To see the result, let’s run the complete script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
from DelphiVCL import * # Create a Class to build a basic Form class MainForm(Form): def __init__(self, Owner): self.Caption = "Introduction to VCL Components" self.Name = "BaseForm" self.SetBounds(10, 10, 500, 450) # Create a Main Panel component pnlMain = CreateComponent('TPanel',Owner) pnlMain.SetProps(Parent=self, Caption="",align = "alClient", Name = "MainPanel") # Page control creation pgConMain = PageControl(pnlMain) pgConMain.Name = "MyPageControl" pgConMain.Parent = pnlMain pgConMain.Align = "alClient" # Tabsheet one pgOne = TabSheet(pnlMain) pgOne.PageControl = pgConMain pgOne.Caption = "Tab 1" # Datetime picker creation dtpDateofIssue = CreateComponent('TDateTimePicker',pgOne) dtpDateofIssue.SetProps(Parent=pgOne) dtpDateofIssue.SetBounds(175,150,125,30) # Initialize your application def main(): Application.Initialize() Application.Title = "MyDelphiApp" f = MainForm(Application) f.Show() FreeConsole() Application.Run() Application.Destroy() main() |
The result:
TDateTimePicker formats date and time values according to the date and time settings in the Regional Settings of the Control panel on the user’s system. Because TDateTimePicker is a wrapper for a Windows control, these formats can’t be changed by changing the formatting variables in the SysUtils unit. However, you can use the Windows API call DateTime_SetFormat to programmatically specify these settings.
Note: The underlying Windows control is known to behave unpredictably when used to set dates in 1752, the year English-speaking countries changed to the Gregorian calendar. Similar problems may appear for different dates when a non-English locale is used. If an application might be used to specify dates on or before the changeover in the current locale (for example, 1918 or before in Russian locales), be sure to test the application using the dates affected.
Check out DelphiVCL which easily allows you to build GUIs for Windows using Python.