Delphi XE 中的集合的工作方式与 D7 中的工作方式不同

发布于 2024-11-19 00:07:19 字数 344 浏览 1 评论 0原文

我在 Delphi 7 程序中有这个常量。它们不在 Delphi XE 下编译。

TYPE
  TSingleChar= AnsiChar;

CONST
  noData: TSingleChar= '.';
  Ambiguity= ['x'];
  DNA_Ambig= ['x', noData]+ Ambiguity;

[DCC 错误] E2026 常量表达式 预计。

  1. XE 中发生了什么变化导致我的旧代码无法编译?
  2. 我认为代码按原样被解释为 Unicode。我说得对吗?

I had this constants in a Delphi 7 program. They are not compiling under Delphi XE.

TYPE
  TSingleChar= AnsiChar;

CONST
  noData: TSingleChar= '.';
  Ambiguity= ['x'];
  DNA_Ambig= ['x', noData]+ Ambiguity;

[DCC Error] E2026 Constant expression
expected.

  1. What was changed in XE that my old code does not compile?
  2. I suppose that the code, as it is, is interpreted as Unicode. Am I correct?

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

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

发布评论

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

评论(2

飞烟轻若梦 2024-11-26 00:07:19

像这样“修复”它:

TYPE
  TSingleChar= AnsiChar;

CONST
  Const_noData = '.';
  noData: TSingleChar= Const_noData;
  Ambiguity= ['x'];
  DNA_Ambig= ['x', Const_noData]+ Ambiguity;

就编译器而言,Const_noData 是一个真正的 const,允许您使用以下命令初始化 noDataDNA_Ambig它。而且您仍然遵循 DRY 原则,即 noData 只有一个定义,即 Const_noData

"Fix" it like this:

TYPE
  TSingleChar= AnsiChar;

CONST
  Const_noData = '.';
  noData: TSingleChar= Const_noData;
  Ambiguity= ['x'];
  DNA_Ambig= ['x', Const_noData]+ Ambiguity;

The Const_noData is a true const as far as the compiler's concerned, allowing you to initialize both noData and DNA_Ambig using it. And you still respect the DRY principle, ie, there's only one definition for noData, the Const_noData.

め可乐爱微笑 2024-11-26 00:07:19
const
  Ambiguity:  TAnsiCharSet = ['B', 'D', 'H'];
  Ambiguity2: TAnsiCharSet = ['C', 'c', 't'] + Ambiguity;

不起作用

const
  Ambiguity = ['B', 'D', 'H'];
  Ambiguity2 = ['C', 'c', 't'] + Ambiguity;

确实有效。类型化常量根本不是真正的常量...

(请注意,这个问题与歧义无关。它是关于什么被认为是常量,什么不是。)

const
  Ambiguity:  TAnsiCharSet = ['B', 'D', 'H'];
  Ambiguity2: TAnsiCharSet = ['C', 'c', 't'] + Ambiguity;

does not work.

const
  Ambiguity = ['B', 'D', 'H'];
  Ambiguity2 = ['C', 'c', 't'] + Ambiguity;

does work. Typed constants aren't really constants at all...

(Notice that the issue has nothing to do with ambiguity. It is about what is considered a constant and what is not.)

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