Delphi:如何重写 ShortDateFormat?

发布于 2024-09-07 01:31:07 字数 385 浏览 7 评论 0原文

我意识到 ShortDateFormat 变量代表用户的偏好。

我还意识到,如果设置发生更改,Delphi 将使用用户的设置自动刷新 ShortDateFormat 变量。

mm/dd/yy

我有一位客户希望所有“短日期”都显示在特定的位置,但他们不希望显示他们的 Windows 首选项。

mm/dd/yyyy

考虑到可以随时重置,在我的应用程序中全局更改 ShortDateFormat 变量的好方法是什么?

注意:包含代码格式的示例日期格式掩码,以使帖子更具视觉吸引力

i realize that ShortDateFormat variable represents the user's preferences.

i also realize that if settings change, Delphi will automatically refresh the ShortDateFormat variable with the user's settings.

mm/dd/yy

i have a customer who wants all "short dates" to be displayed in a particular, but they don't want to their Windows preferences.

mm/dd/yyyy

What is a good way to globally, in my application, change the ShortDateFormat variable, given that it can be reset at any time?

Note: example date format masks in code format included to make the post more visually appealing

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

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

发布评论

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

评论(2

柒夜笙歌凉 2024-09-14 01:31:07

拥有您自己的 FormatSettings 并将其与所有格式例程一起显式使用,而不是使用隐式版本。

它还具有线程安全的优点。

function DateTimeToStr(const DateTime: TDateTime): string;

function DateTimeToStr(const DateTime: TDateTime; const FormatSettings: TFormatSettings): string;

更新:为避免您的应用程序对区域设置更改做出反应,您可以将 Application.UpdateFormatSettings 更改为 False
TApplication.Create 中默认为 True
但请注意,这并不是对所有设置 100% 安全,因为某些例程会直接获取 ThreadLocale。

Have your own FormatSettings and use it explictly with all the format routines instead of using the implicit version.

It has also the advantage of being Thread safe.

function DateTimeToStr(const DateTime: TDateTime): string;

function DateTimeToStr(const DateTime: TDateTime; const FormatSettings: TFormatSettings): string;

Update: to avoid your application to react to locale changes, you can change Application.UpdateFormatSettings to False.
It is defaulted to True in TApplication.Create.
But beware this is not 100% bulletproof for all settings as some routines go get the ThreadLocale directly.

伪心 2024-09-14 01:31:07

我同意 François 的观点,但我想提一下另一个选项:设置

Application.UpdateFormatSettings := False;

为防止在 Windows 中全局更改格式设置时自动更新格式设置。

I agree with François, but I want to mention another option: set

Application.UpdateFormatSettings := False;

to prevent automatic updating of format settings when they are changed globally in Windows.

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