The ZFormatSettings unit and how it works is very nice. There is an issue, however, because while you can set various formats, you can't set the date or time separators, and so if they get changed from the regional defaults the library routines used for conversions won't work. For example if my regional date separator is '/', and I set ZConn.FormatSettings.EditTimestampFormatSettings.Format := 'YYYY-MM-DD HH:NN:SS'; then TZAbstractTimestampFormatSettings.TryStrToTimestamp won't work (just picking one example.)
To solve it I added time and date separator checking and setting to all of the various "SetFormat" methods. This works well for date and time, but not for timestamps. However I also added them to SetDateformat and SetTimeFormat of the TZAbstractTimestampFormatSettings object and so as long as you set them the correct separators will be used. I also had to add the DateFormat and TimeFormat properties to TZEditTimestampFormatSettings.
So that fixes things, or at least allows them to work properly, but I'm guessing a more elegant solution could be found. Currently TimestampFormats keep their "full format" in LongDateFormat, maybe that should be removed and set date and time formats for timestamps individually?
Thanks
- Mark
ZFormatSettings issues related to separators
Re: ZFormatSettings issues related to separators
Update. Another options is to always set XXXFormatSettings.FormatSettings to a TFormatSettings object with the values you need before using the various .Format properties. Note that you still need to set the individual format properties or it will default to the system FormatSettings object, which may have different settings.
-Mark
Code: Select all
// Initialize the FormatSettings with our own pre-filled in one. This will set the separators and any other things we want to change.
ZConn.FormatSettings.DisplayTimeStampFormatSettings.FormatSettings := MyFormatSettings;
// Now also set the individual formats.
ZConn.FormatSettings.DisplayTimestampFormatSettings.Format := TimeStampFormat;
ZConn.FormatSettings.DisplayTimestampFormatSettings.DateFormat := DateFormat;
ZConn.FormatSettings.DisplayTimestampFormatSettings.TimeFormat := TimeFormat;
ZConn.FormatSettings.DisplayTimeFormatSettings.SecondFractionOption := foRightZerosTrimmed;
ZConn.FormatSettings.DisplayTimestampFormatSettings.SecondFractionOption := foRightZerosTrimmed;