You can restrict the values that are allowed for a property to members of an enumeration class. Define the property as restricted to a specific enumeration class in the class definition using this syntax:
propertiesPropNameEnumerationClassend
This syntax restricts values ofPropName
to members of the enumeration classEnumerationClass
.
For example, theDays
class defines a property namedToday
. The allowed values for theToday
property are enumeration members of theWeekDays
class.
TheWeekDays
class defines the enumerations:
classdefWeekDaysenumerationMonday, Tuesday, Wednesday, Thursday, Fridayendend
Use theWeekDays
enumerations to restrict the allowed values of theToday
property:
classdefDayspropertiesTodayWeekDaysendend
Create an object of theDays
class.
d = Days; d.Today = WeekDays.Tuesday;
d = Days with properties: Today: Tuesday
The automatic conversion feature enables users of theDays
类赋值的Today
property as either enumeration members,char
vectors, or string scalars. TheToday
property is restricted to members of theWeekDays
enumeration class. Therefore, you can assign achar
vector that represents a member of theWeekDays
class.
d = Days; d.Today ='Tuesday';
Also, you can use a string scalar:
d = Days; d.Today ="Tuesday";
For more information on restricting property values, seeValidate Property ValuesandProperty Class and Size Validation.