首页 > 其他 > 详细

W1002 Symbol 'Create' is specific to a platform

时间:2015-02-06 14:49:41      阅读:400      评论:0      收藏:0      [点我收藏+]

http://stackoverflow.com/questions/9099892/how-to-use-tformatsettings-create-without-being-specific-to-a-platform

 

 

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 way to do this, so that I do not get a warning?

shareedit
 

3 Answers

You have two options 你有2个选择

1) Use the overload version which uses a string instead of a TLocaleID 使用一个具体的LCID字符串

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

2) Disable the warning locally 临时禁用 这个Warn 编译器开关。

{$WARN SYMBOL_PLATFORM OFF}
    fSettings := TFormatSettings.Create(LOCALE_USER_DEFAULT);
{$WARN SYMBOL_PLATFORM ON}
shareedit
 
5  
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 ‘12 at 17:20 如果你 从来不 开发 Windows平台以外的软件,直接全局关闭这个 Warn
    
If I choose to use the string version, what is the string that is equivalent to LOCALE_USER_DEFAULT? – croceldon Feb 1 ‘12 at 18:49
    
try using an empty string or the constructor without parameters, this will call the GetThreadLocale function internally. just be careful with the calls to SetThreadLocale because can change the result of this function. –  RRUZ Feb 1 ‘12 at 18:59
 

My code is now written as follows:

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

You will probably want to adjust that IFDEF for appropriate future versions, but it gives the idea.

shareedit
 
    
This snippet actually is by magnitude more specific to platform than which compiler complains about. – OnTheFly Feb 1 ‘12 at 18:43
    
@user539484 Perhaps, but IIRC I got it from the help as the recommended way. –  mj2008 Feb 2 ‘12 at 9:29

There are different overloads of TFormatSettings.Create. The one with an LCID is specific to Windows. The one without any parameters and the one taking a locale name as a string are more portable.

Or you could suppress the warning for platform-specific units and procedures, if you know your software will never be used for anything other 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 dead as can be, making your code portable to those platforms may be a waste of time.

shareedit

W1002 Symbol 'Create' is specific to a platform

原文:http://www.cnblogs.com/CodeGear/p/4277063.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!