Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi: How to have non-contiguous subrange enumeration type?

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?

like image 969
Ian Boyd Avatar asked Dec 03 '25 00:12

Ian Boyd


2 Answers

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.

like image 56
Mason Wheeler Avatar answered Dec 05 '25 22:12

Mason Wheeler


Could you use a set instead?

TSomeCharSet= Set of Char;

SomeChars: TSomeCharSet = [' ','A','B','C','D','E','F','R'];

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.

like image 20
Despatcher Avatar answered Dec 05 '25 23:12

Despatcher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!