问题
I can easily declare a enumeration and a set.
But sometimes I want to work with only part of the enumeration and I'd like the compiler to check for me if values in the sub-enum and its subset stay within the bounds.
type
TDay = (mon, tue, wen, thu, fri, sat, sun);
TWeekday = (mon..fri); //not allowed;
TDays = set of TDay;
TWeekdays = set of TDay[mon..fri]; //not allowed
Can I declare TWeekday and TWeekdays as a derivative of TDay, if so, how?
Funny enough google does not yield anything (for me) on this issue, just plain old sets.
回答1:
You've got the wrong syntax for the subrange. Drop the brackets () and it will work.
type
TDay = (mon, tue, wen, thu, fri, sat, sun);
TWeekday = mon..fri; // A subrange of TDay
TDays = set of TDay;
TWeekdays = set of TWeekDay;
More about Subrange Types and Sets.
来源:https://stackoverflow.com/questions/29819590/declaring-a-type-as-a-subset-of-a-set