ZFormatSettings issues related to separators

The offical for ZeosLib 7.3 Report problems, ask for help, post proposals for the new version of Zeoslib 7.3/v8
Quick Info:
-We made two new drivers: odbc(raw and unicode version) and oledb
-GUID domain/field-defined support for FB
-extended error infos of Firebird
-performance ups are still in queue
In future some more feature will arrive, so stay tuned and don't hassitate to help
Post Reply
MJFShark
Expert Boarder
Expert Boarder
Posts: 218
Joined: 04.06.2020, 13:59

ZFormatSettings issues related to separators

Post by MJFShark »

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
MJFShark
Expert Boarder
Expert Boarder
Posts: 218
Joined: 04.06.2020, 13:59

Re: ZFormatSettings issues related to separators

Post by MJFShark »

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.

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;
-Mark
Post Reply