How to use TFormatSettings.Create without being platform specific?

Delphi XE has the following:

fSettings := TFormatSettings.Create(LOCALE_USER_DEFAULT); 

But I always get a compilation warning:

 W1002 Symbol 'Create' is specific to a platform 

What is the correct way to do this so that I don't get a warning?

+7
source share
3 answers

You have two options.

1) Use an overload version that uses a string instead of TLocaleID

 class function Create(const LocaleName: string): TFormatSettings; overload; static; 

2) Disable the warning locally

 {$WARN SYMBOL_PLATFORM OFF} fSettings := TFormatSettings.Create(LOCALE_USER_DEFAULT); {$WARN SYMBOL_PLATFORM ON} 
+12
source

There are different TFormatSettings.Create overloads. An object with an LCID is Windows specific. A simpler hyphenation that does not contain any parameters, and one that takes the locale name as a string, is more hyphenated.

Or you can suppress the warning for modules and procedures for the platform if you know that your software will never be used for anything other than Delphi for Windows. VCL contains traces of modern unsupported platforms such as Linux (Kylix) and .NET (Delphi.NET), and since they are just as dead as your portable code on these platforms can be a waste of time.

+2
source

My code is now written as follows:

 {$IFDEF VER220} FormatSettings := TFormatSettings.Create(GetThreadLocale); {$ELSE} GetLocaleFormatSettings(GetThreadLocale, FormatSettings); {$ENDIF} 

You will probably want to configure IFDEF for the relevant future versions, but this gives an idea.

+2
source

All Articles