Delphi:如何拥有非连续子范围枚举类型?
虽然以下子范围枚举声明有效:
type
TReceiptCode = 'A'..'F';
这不起作用:
type
TReceiptCode = ' ','A'..'F', 'R';
也不起作用
type
TReceiptCode = ' ','A','B','C','D','E','F','R';
如何声明具有非连续值的子范围类型?
While the following subrange enumeration declaration works:
type
TReceiptCode = 'A'..'F';
This does not:
type
TReceiptCode = ' ','A'..'F', 'R';
Nor does
type
TReceiptCode = ' ','A','B','C','D','E','F','R';
How can i declare a subrange type with non-contiguous values?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不幸的是,我认为没有任何办法可以做到这一点。您可以声明一个(新的)非连续枚举,或现有类型的子范围,但不能同时声明两者。
Unfortunately, I don't think there's any way to do that. You can declare a (new) non-contiguous enumeration, or a subrange of an existing type, but not both.
可以用一套代替吗?
可能是奶奶和鸡蛋的情况,但我不确定你当时用的是什么:) ...
那么你剩下的就是使用 Set 或数组作为限制“范围”自己创建 TNonContigousCharRange 并在以下情况下引发异常它超出范围或有 SetReceiptCode 过程来执行类似的操作。
Could you use a set instead?
Could be granny and egg situation but I'm not sure what you are using then for :) ...
Well all you are left with then is creating TNonContigousCharRange yourself using a Set or array as the limiting "Range" and raising an exception when it is out of range or having a SetReceiptCode procedure to do a similar thing.
对于之前的所有答案,我想简单地补充一点,线索就在类型的名称中: subrange
简而言之,范围有下限和上限。您所描述的是一个集合(或一个子集),而不是一个子范围,因此您当然不能将其表达为子范围。
To all previous answers I would add simply that the clue is in the name of the type: subrange
Simply put, a range has a lower and an upper bound. What you describe is a set (or a subset), not a subrange so of course you cannot express it as a subrange.