如何在不特定于平台的情况下使用 TFormatSettings.Create?

发布于 2025-01-01 10:17:56 字数 241 浏览 4 评论 0原文

我在 Delphi XE 中有以下内容:

fSettings := TFormatSettings.Create(LOCALE_USER_DEFAULT);

但我总是在编译时收到警告:

W1002 Symbol 'Create' is 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

谁把谁当真 2025-01-08 10:17:56

您有两个选择

1) 使用重载版本,该版本使用字符串而不是 TLocaleID

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

2)本地禁用警告

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

You have two options

1) Use the overload version which uses a string instead of a 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}
小…红帽 2025-01-08 10:17:56

TFormatSettings.Create 有不同的重载。带有 LCID 的是 Windows 特有的。不带任何参数的方法和将语言环境名称作为字符串的方法更可移植。

或者,如果您知道您的软件永远不会用于 Delphi for Windows 以外的任何其他用途,您可以抑制针对特定于平台的单元和过程的警告。 VCL 包含现在不受支持的平台的痕迹,例如 Linux (Kylix) 和 .NET (Delphi.NET),并且由于它们已经死了,因此将代码移植到这些平台可能会浪费时间。

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.

柳若烟 2025-01-08 10:17:56

我的代码现在编写如下:

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

您可能想要调整 IFDEF 以适应未来的版本,但它给出了这个想法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文