Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Formatting Data in Data Aware Controls - override default TFormatSettings ?



Permlink Replies: 1 - Last Post: Oct 9, 2015 1:14 PM Last Post By: Lajos Juhasz Threads: [ Previous | Next ]
Leon Sinagra

Posts: 1
Registered: 9/13/15
Formatting Data in Data Aware Controls - override default TFormatSettings ?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 7, 2015 1:49 AM
Can anyone please tell me if I am using Data Aware Controls (e.g. DB Edit) and have a date field from my database connected to it, and I want to display it in the format 25-12-2015 (i.e. Christmas day) how I should go about it.
I am upgrading my application from Delphi 5 to Delphi 10 Seattle (RAD Studio 10 Seattle) and the previous method I used (DateSeperator "= "-") is not possible as these have been superseded by TFormatSettings

Previously when I used DateSeperator := "-" this one line would override the corresponding default locale setting for all data aware components connected to date fields.
I have seen comments to use the new TFormatSettings to read the locale settings into a variable and then pass this to formatting functions to format your data as required and then display your data, which is all now being thread safe.
However I would not expect that this is to be done for every data field for every data aware control, as they are all automatically connected to data in the database, they are not just text / labels I am trying to format.

The other option is to use the DipslayFormat property of data aware controls, but then this property will need to be set for all data aware components, and then if the locale (or region) is changed in the PC control panel the display format property will override the locale change.

The question is ?
Is it possible to override one property of a locale setting within an application (e.g. as before when DateSeperator := "-" was used) and retain all the other defaults settings with a simple few lines of code, and do this in the new thread safe way incorporating the use of TFormatSettings ? So that all data aware controls will use the new locale property when displaying their data.

Thanks and Regards,

Lajos Juhasz

Posts: 801
Registered: 3/14/14
Re: Formatting Data in Data Aware Controls - override default TFormatSettings ?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 9, 2015 1:14 PM   in response to: Leon Sinagra in response to: Leon Sinagra
Leon Sinagra wrote:

The question is ?
Is it possible to override one property of
a locale setting within an application (e.g. as before when
DateSeperator := "-" was used) and retain all the other defaults
settings with a simple few lines of code, and do this in the new
thread safe way incorporating the use of TFormatSettings ? So that
all data aware controls will use the new locale property when
displaying their data.

For that purpose you can use the global FormatSettings variable to se
Dateseparator:
FormatSettings.DateSeparator:='-';

or to change the format:

FormatSettings.ShortDateFormat:='dd-mm-yyyy';
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02