Project members: Enum
With the enum member you can add a user-defined enumeration data type consisting of uniquely named enumerators. Once defined, this data type can serve in the declaration of any data member within your project. At the runtime, the affected data member can assume exactly one of the enumerators listed within the corresponding enum member. Enum members are represented in Composer by following bricks:
Please note, an enum member can exist only within a unit member.
Add new enum
★First switch to the Composer page for the respective unit member you want to add the new enum member.
★Then, in the Gallery window, ensure that the folder Chora is opened.
★Look in the folder for the template named Enum.
★With the mouse, select the template and drag it into the Composer.
★Drop the template within the Composer.
Adding a new enum member.
Name the enum
★First ensure, that the enum member is selected.
★Press the key F2 or select the menu item .
★Enter the new name in the Inspector window.
Enum members have a global character - they can be accessed from everywhere within your project. To address an enum member, you must always use its full name, which is composed of the unit name, the member is defined inside, and the name of the member itself, both separated by :: (double colon) signs. For example Core::KeyCode.
Edit the enum
Every enum member can contain any arbitrary number of enumerator members. To add a new or edit existing enumerators open the enum member in a new Composer page:
★First ensure, that the enum member is selected.
★Press the key ENTER ...
★... or double click on the enum member with the mouse.
Please note, newly added enum members contain already few dummy enumerators called per default FirstItem, SecondItem and so far. Feel free to rename or delete them.
Duplicate an existing enum
You can create any number of copies of an already existing enum member.
★First ensure, that the enum member is selected.
★Press the keys CtrlC and CtrlV in succession ...
★... or hold the key Ctrl pressed while you drag and drop the selected enum member.
★Finally rename the just duplicated enum member.
You can also Drag & Drop an enum member from the Browser into the Composer window and create so a duplicate of the affected member:
★First switch to the Composer page for the respective unit member, where you want to add the duplicate of the enum.
★Then ensure that the Browser window is visible.
★Within the Browser window locate the desired enum member. This can be done easily with Browser's own filter function.
★Select this enum member in the Browser window.
★Drag and drop the selected enum member into the Composer:
Duplicating an enum by simply Drag & Drop it between the Browser and Composer windows
★Finally rename the just duplicated enum member.
Use the enum member in data member declarations
Every enum member represents an individual user defined enumeration data type, you can use in the declaration of variables, properties, arrays, local variables, local arrays as well as in parameter and return type declaration of a method. The enumeration data type corresponds to the full name of the enum member, composed of the unit name, the member is defined inside, and the name of the member itself, both separated by :: (double colon) signs. For example:
// Declare a local variable of the 'Core::KeyCode' enumeration type var Core::KeyCode keyCode;
Use the enum member in expressions
The name of the enum member can be used within Chora expressions to form a literal of the corresponding enumeration data type. The literal is composed of the enumeration data type name and the name of a particular enumerator member defined inside the enum, both separated by the . (dot) sign. For example:
// Declare a local variable of the 'Core::KeyCode' enumeration type var Core::KeyCode keyCode = ...; // Does the variable store a value corresponding to the enumerator 'Left' // defined within the enumeration data type 'Core::KeyCode'? if ( keyCode == Core::KeyCode.Left ) trace "Evidently, the user has pressed the key 'left'.";
Control the code generation
With the attribute Generator you can selectively control, whether the enum member should be taken in account during the code generation or not. Configuring this attribute with the value false will exclude the member from your project unless the member name is explicitly involved within a Chora expression or data member declaration.
Delete an enum
★First ensure, that the enum member is selected.
★Press the key DEL or select the menu item .
Attributes of an enum
The following table shows the complete list of attributes provided by the enum member:
Attribute name |
Short description |
---|---|
Determines the position and the size of a enum member brick within the Composer window. |
|
Contains the description for the enum member. |
|
Controls the code generation for the affected enum member. |