Delphi 中具有自定义值的枚举
在 Delphi 5 中可以像这样声明带有自定义值的枚举吗?:
type
MyEnum = (meVal1 = 1, meVal2 = 3); // compiler error
谢谢!
It is possible to declare enums with custom values in Delphi 5 like this?:
type
MyEnum = (meVal1 = 1, meVal2 = 3); // compiler error
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您有旧版本的 Delphi (<= D5 IIRC),则无法执行此操作。也许你可以用常量替换枚举? 不幸的是
,编译器无法像使用枚举类型那样为您执行尽可能多的错误检查。
If you have an older version of Delphi (<= D5 IIRC) you can't do this. Maybe you can replace the enum by constants? Something like
Unfortunately, the compiler can't do as much error checking for you with this as with an enum type.
作为 Ulrich 答案的一个有点丑陋的扩展,你可以做如下的事情:
并以
“不漂亮”的方式访问它们,我同意你,但至少这样你可以对那些早期版本的 Delphi 进行更多的编译器错误检查。
As a somewhat ugly extension to the answer by Ulrich you could do something like the following:
and access them as
Not pretty, I grant you, but at least that way you get a little more compiler error checking for those earlier versions of Delphi.
在旧的德尔菲斯你可以做
In older Delphis you can do
根据这篇文章,这是合法的。我确实记得在 Delphi 的早期版本中不支持提供值。
提供您收到的“编译器错误”可能会有所帮助。另外,你用的Delphi是什么版本?
This is legal according to this article. I do recall that in early versions of Delphi supplying values wasn't supported.
It might help to provide the 'compiler error' you received. Also, what version of Delphi are you using?