本文介绍了ShortDateFormat与FormatSettings.ShortDateFormat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 在尝试让Log4D在XE4中进行编译时,我看到In trying to get Log4D to compile in XE4, I was seeing 在此行:SetOption(DateFormatOpt, ShortDateFormat); 有点谷歌搜索使我想到了更改 ShortDateFormat 到 FormatSettings.ShortDateFormat ,从而在XE4上导致以下编译代码:A bit of googling led me to the solution of changing ShortDateFormat to FormatSettings.ShortDateFormat, which led to the following compiling code on XE4:SetOption(DateFormatOpt, FormatSettings.ShortDateFormat); 但是,我不太理解为什么为什么可以解决问题需要指定 FormatSettings ,因为我已经在我的uses语句中包含了 SysUtils ,其次,我不确定如何重写此行以继续与该开源项目已支持的Delphi版本向后兼容。However, I don't really understand why that fixes things why it's needed to specify FormatSettings since I already included SysUtils in my uses statement, and secondly, I'm not sure how to rewrite this line to continue to be backward compatible with the versions of Delphi this open source project already supports.我想我可以在该参数或代码行周围添加一个IFDEF无论Delphi引入了什么版本的 FormatSettings -但我什至不知道这是什么版本的Delphi,更不用说这是解决此问题的好方法。 / p> I suppose I could add an IFDEF around that parameter or line of code for whatever version of Delphi introduced FormatSettings - but I'm not even sure what version of Delphi that was, let alone whether that's a good or bad way to solve this problem.推荐答案最终在XE3中删除了全局 SysUtils.ShortDateFormat ,请参见 全局变量 。 The global SysUtils.ShortDateFormat was finally removed in XE3, see Global Variables. 在现代Delphi版本中,也不建议使用全局 FormatSettings 变量记录。主要原因是它不是线程安全的(旧的全局 ShortDateFormat 也会受到影响)。您应该定义自己的 TFormatSettings 变量,该变量在整个范围内都是一致的。In modern Delphi versions, the global FormatSettings variable record is also not recommended to use. Main reason is that it is not thread safe (which the old global ShortDateFormat also suffered from). You should define your own TFormatSettings variable that is consistent throughout your scope.这还将使您的代码向后兼容。This will also make your code backwards compatible.但是,初始化 FormatSetting 记录的方式因Delphi版本而异。However, the way to initialize your FormatSetting record varies between Delphi versions.在旧版本(D7 +)上使用:On older versions (D7+) use:GetLocaleFormatSettings(GetThreadLocale, FormatSettings);在较新版本(XE +)中:And in newer versions (XE+):FormatSettings := TFormatSettings.Create(GetThreadLocale); // Or one of the overloads 这篇关于ShortDateFormat与FormatSettings.ShortDateFormat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-28 17:07