androiddelphilocalefiremonkeydelphi-xe5

How to Correctly Fetch the Decimal Separator Character on Android


It was quite easy to get the char from using an old way like this:

var
FS:TFormatSettings;
  begin
    FS:=TFormatSettings.Create;
...

Record member FS.DecimalSeparator will contain the reuired Char. This method have been working fine in Win FMX applications compiled by my XE5 IDE. But looking for the proper ways of fething the character in FireMonkey I read some opinions that this way is pernicious and deprecated. I also read that this is not supported by later versions of Delphi (I can not check it myself). But what then will be the proper and reliable way? Especially if the code is expected to be capable of migrating to Android?


Solution

  • The DecimalSeparator global variable is what was deprecated, along with all the other locale related global variables. They have now been removed.

    The new and supported way to access this information is through TFormatSettings. So contrary to your question, that type is not deprecated. Quite the opposite, it is the recommended way to obtain locale information.

    var
      fs: TFormatSettings;
    ....
    fs := TFormatSettings.Create;
    // use fs.DecimalSeparator;