Delphi:如何重写 ShortDateFormat?
我意识到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
拥有您自己的 FormatSettings 并将其与所有格式例程一起显式使用,而不是使用隐式版本。
它还具有线程安全的优点。
更新:为避免您的应用程序对区域设置更改做出反应,您可以将
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.
Update: to avoid your application to react to locale changes, you can change
Application.UpdateFormatSettings
toFalse
.It is defaulted to
True
inTApplication.Create
.But beware this is not 100% bulletproof for all settings as some routines go get the ThreadLocale directly.
我同意 François 的观点,但我想提一下另一个选项:设置
为防止在 Windows 中全局更改格式设置时自动更新格式设置。
I agree with François, but I want to mention another option: set
to prevent automatic updating of format settings when they are changed globally in Windows.