During add Delphi 5 compatibility to the Purchase Order calculation sample of HotXLS Delphi Excel Spreadsheet component, an error occurred while compiling under Delphi 5.
The line which set the date format of the TDateTimePicker control does not compile:
1 |
DateTimePicker.Format := 'MM/dd/yyyy'; |
TDateTimePicker control of Delphi is a wrapper around a Microsoft control. It allows you to show the date in one of two formats (long and short), but in Delphi 5 and lower, it did not allow you to change the DateTime format. That’s because it uses the Windows date and time settings, not Delphi’s internal format variables like “ShortDateFormat”.
In Delphi 6 and later, you can use the Format property to change the display of date or time.
In Delphi 5 and earlier, you should use the DateTime_SetFormat function to set the format, this function in the “CommCtrl” unit, you should add CommCtrl to the “USES” column, otherwise, the DateTime_SetFormat won’t be recognized.
The fix for our sample project looks like this:
1 2 3 4 5 |
{$IFDEF D5} DateTime_SetFormat(DateTimePicker.Handle, PChar('MM/dd/yyyy')); {$ELSE} DateTimePicker.Format := 'MM/dd/yyyy'; {$ENDIF} |