zoukankan      html  css  js  c++  java
  • W1002 Symbol 'Create' is specific to a platform

    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
  • 相关阅读:
    rhel 7.0 配置centos yum源(2016/12/8),成功!
    rosetta2014/2015安装时出现INCLUDE(keyerror)错误,解决。
    显示python已安装模块及路径,添加修改模块搜索路径
    sort
    linux 查看磁盘剩余命令
    cat hesA/Models/score_tgt.sc| awk '{ print $2,$19}' | sort -n -k 1
    Python_sys模块
    Python_os模块
    Python_datetime模块
    Python_time模块
  • 原文地址:https://www.cnblogs.com/CodeGear/p/4277063.html
Copyright © 2011-2022 走看看