Delphi XE2和Delphi XE7中的LongMonthNames用法

时间:2014-12-08 12:57:25

标签: delphi delphi-xe2 delphi-xe3 delphi-xe7

为什么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.

1 个答案:

答案 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