Http://stackoverflow.com/questions/9099892/how-to-use-tformatsettings-create-without-being-specific-to-a-platform
How to use tformatsettings.create without being specific to a platform?
| Up vote5down votefavorite 2 |
I have the following in Delphi XE: fSettings := TFormatSettings.Create(LOCALE_USER_DEFAULT);
But I always get a warning on compile: W1002 Symbol ‘Create‘ is specific to a platform
What is the correct-a-do-this, so-I do not get a warning? Delphi Delphi-xe
| ShareEdit |
Asked Feb 1 ' at 16:57croceldon 1,0553 |
|
|
Add a Comment |
3 Answersactiveoldestvotes
| Up vote10down voteaccepted |
you have two options and you have 2 options 1) Use the overload version which uses a string instead of aTLocaleID 使用一个具体的LCID字符串 class function Create(const LocaleName: string): TFormatSettings; overload; static;
2) Disable The warning locally temporarily disables this warn compiler switch. {$WARN SYMBOL_PLATFORM OFF} fSettings := TFormatSettings.Create(LOCALE_USER_DEFAULT);{$WARN SYMBOL_PLATFORM ON}
| ShareEdit |
answered Feb 1 ' at 17:15rruz 102k8204353 |
|
|
|
|
option 3. Disable the warning globally. If you never build for platforms other than Windows, there ' s not much point in enabling it at All. – david Heffernan feb 1 ' at 17:20 if you never develop software other than Windows platform, direct global shutdown of this Warn |
|
|
if I choose to use the string version, What's the string that's equivalent to Locale_user_default? – croceldon feb 1 ' at 18:49 |
|
|
Try using an empty string or the constructor without parameters, this would call the Getthreadlocale function internally. Just be careful with the calls to SetThreadLocale because can change the result of this Function.–rruz Feb 1 ' 18:59 |
Add a comment |
| Up vote1down vote |
My code is now written as follows: {$IFDEF VER220} FormatSettings := TFormatSettings.Create(GetThreadLocale);{$ELSE} GetLocaleFormatSettings(GetThreadLocale, FormatSettings);{$ENDIF}
You'll probably want to adjust this ifdef for appropriate future versions and it gives the idea.
| ShareEdit |
answered Feb 1 ' at 17:52mj2008 4,8971 |
|
|
|
|
this snippet actually is by magnitude More specific to platform than which compiler complains About. – onthefly feb 1 ' at 18:43 |
|
|
@user539484 perhaps, but IIRC I got it from the help as the recommended. –mj2008 Feb 2 ' at 9:29 |
Add a comment |
| Up vote2down vote |
There is different overloads of TFormatSettings.Create . The one and an LCID are specific to Windows. The one without any parameters and the one taking a locale name as a string is more portable. Or you could suppress the warning for platform-specific units and procedures, if you know your software would never be used For anything and than Delphi for Windows. The VCL contains traces of now unsupported platforms such as Linux (Kylix) and. NET (Delphi.NET), and since they ' re as DEA D as can, making your code portable to those platforms could be a waste of time.
| ShareEdit |
answered Feb 1 ' at 17:09hvd 51.9k6123 |
|
W1002 Symbol ' Create ' is specific to a platform