为什么LongMonthNames[X]
单独(没有名称空间前缀)在Delphi XE7中不起作用,而它在Delphi XE2中工作?
program LongMonthNames_Test;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
begin
try
// Works in both Delphi XE2 and Delphi XE7:
Writeln(System.SysUtils.FormatSettings.LongMonthNames[12]);
// Works only in Delphi XE2, does NOT work in Delphi XE7:
// ("not work" obviously means does not compile because of errors in the source code)
Writeln(LongMonthNames[12]);
Readln;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
答案 0 :(得分:5)
在XE2中,LongMonthNames
单位中deprecated
仍然是它自己的全局变量(在XE中为SysUtils
)。在XE3中,该变量已被删除。您必须使用LongMonthNames
的{{1}}成员,该成员在TFormatSettings
单元中具有全局变量:
SysUtils
您不必编写完全合格的路径,只需var
// Note: Using the global FormatSettings formatting variables is not thread-safe.
FormatSettings: TFormatSettings;
即可:
FormatSettings.LongMonthNames[x]
如果您创建自己的Writeln(FormatSettings.LongMonthNames[12]);
实例,则可以安全地在线程中使用(只要遵守通常的线程安全规则):
TFormattSettings