Is there a consistent global variable FormatSettings availabe?

I know that there is a global variable FormatSettings , which is initialized by the current regional OS settings at startup. This means that when converting strings to numbers and visa verses, for example, in an xml file, you exchange files with other PCs. It may happen that such a file cannot be loaded, since lines can no longer be converted back to numbers. It depends on the DecimaleSeparator .

So my question is: is there another FormatSettings variabel globule FormatSettings that I can use to store persistent data in a text file?

Example:

 FloatToStr(Value, PersistentFormatSettings); 
+4
source share
2 answers

No, there is no such variable. However, you can define it yourself. Declare it in a block, and then use this block where you need your language-independent settings.

+2
source

In modern versions of Delphi, the global variable FormatSettings deprecated (mainly because they are not thread safe). Each RTL function that uses formatting variables has been overloaded to take an optional TFormatSettings entry as input. This allows not only the use of formatting options depending on a specific topic, but also customizable formatting options for each use, without affecting the use of other formats. For instance:

 var Fmt: TFormatSettings; S: String; begin Fmt := TFormatSettings.Create; // get default settings // // or: // Fmt := TFormatSettings.Create(SomeLocaleID); // get locale-specific settings // // or: // Fmt := TFormatSettings.Create(SomeLocaleName); // get locale-specific settings // // customize its fields to use whatever you want... Fmt.DecimalSeparator := ...; Fmt.ThousandSeparator := ...; // now format it... S := FloatToStr(Value, Fmt); end; 
+2
source

Source: https://habr.com/ru/post/1489426/


All Articles