W1002 Symbol 'Create' is specific to a platform

本文探讨了在Delphi中使用TFormatSettings.Create方法时遇到的警告问题,提供了两种解决方案:一是使用带有字符串参数的重载版本,二是局部禁用警告。同时讨论了如何避免平台特定的警告,并给出了代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

up vote10down voteaccepted

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

转载于:https://www.cnblogs.com/CodeGear/p/4277063.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值