|
|
|
|
- Declaring enumerations
- Passing an enumeration as a parameter to a procedure
- Special cases
- Extension of enumeration
- Creating aliases in an enumeration
- Associated values
- Associated properties
- Available WLanguage functions
- Limits
Enumeration (Type of variable) In french: Enumeration
An enumeration is a set of values. An Enumeration variable or parameter can only be assigned with a value of the enumeration. // Declaration code // Declare an enumeration RobotType is Enumération Walk Stopped InMaintenance OutOfOrder END
// Declare an Enumeration variable Post1 is RobotType // Assign the variable Post1 = Walk // Post1 = 1 // Displays a compilation error // Post1 = "Walk" // Displays a compilation error
Syntax
Declaring an enumeration Hide the details
<Enumeration name> is Enumeration <Enumeration values> END
<Enumeration name>: Name of enumeration to declare <Enumeration values>: Different values that can be taken by the enumeration. <END>: End of declaration.
Declaring an Enumeration variable Hide the details
<Variable name> is <Enumeration name>
<Variable name>: Name of Enumeration variable to declare. <Enumeration name>: Name of enumeration that was declared beforehand. The default enumeration value corresponds to the first enumeration value. Remarks An enumeration must be declared in: - The project initialization code in order to be used in all the processes of the project (code of project, code of windows, code of controls, procedures, etc.).
- The declaration code of global variables of a window in order to be used in all the processes of the window (code of window, code of controls found in the window, local procedures, etc.).
- The opening code of a report in order to be used in all the processes of the report (code of the report, code of controls found in the report, local procedures, etc.).
- The declaration code of a class in order to be used in the class.
- To access this enumeration from a class method, use the following syntax:
- To access this enumeration from a code external to the class, use the following syntax:
"<Class name>::<Enumeration name>"
- The declaration code of sets of procedures in order to be used in all the procedures of the set.
Remark: An enumeration is always global: - to a project,
- to a window,
- to a report,
- to a class.
Passing an enumeration as a parameter to a procedure An Enumeration variable can be passed as a parameter to a procedure. To do so, use the following syntax: <Procedure name>(<Name of enumeration variable>) For example: // Procedure with an Enumeration parameter PROCÉDURE OperatingMode(p is RobotType) // Calls with an Enumeration parameter OperatingMode(Walk) OperatingMode(1) // Displays a compilation error OperatingMode("A") // Displays a compilation error
Special cases - Assisted input: The assisted input for an enumeration parameter proposes the different enumeration values.
- Order of values: The <, <=, >, >= operators are available for the enumerations as well as the automatic sort operations (ArraySort, ArraySeek, etc.). The order of values in the enumeration is the order in which the values are declared.
Example:
// Declaration code // Declare an enumeration RobotType is Enumération Walk Stopped InMaintenance OutOfOrder END // Declare an Enumeration variable Post1 is RobotType // Assign the variable Post1 = Walk ... IF Post1>Stopped THEN Info("The robot encounters a problem") END
Extension of enumeration An enumeration can extend the values of one or more other enumerations by taking the values of this ones and by adding new values. The following syntax is used: <Enumeration name> is Enumeration [Base Enumeration] <Additional values of enumeration> END where: - Enumeration name: Name of enumeration that was declared beforehand.
- Base Enumeration: Name of base enumeration to use.
- Additional Values of Enumeration: Additional values that will be taken into account in the enumeration.
Example: // Declaration code // Declare an enumeration RobotType is Enumération Walk Stopped InMaintenance OutOfOrder END AdvancedRobotType is Enumération [RobotType] InLoop END
Assigning an extended value in a base enumeration is not allowed. Creating aliases in an enumeration You have the ability to declare aliases to insure a temporary compatibility for example. The following syntax is used: <Enumeration name> is Enumeration <Value 1 of enumeration> <Value 2 of enumeration> <Value 3 of enumeration> = <Value 1 of enumeration> END Example: // Declaration code // Declare an enumeration RobotType is Enumération Walk Stopped InMaintenance OutOfOrder // Declare the temporary aliases Maintenance = InMaintenance Breakdown = OutOfOrder END
Associated values In WLanguage, a constant value of simple type can be associated with each value of an enumeration. This value is associated with the enumeration value in the enumeration declaration. // Declare the enumeration with associated values RobotType is Enumération Walk = "Running the robot" Stopped = "Robot stopped" InMaintenance = "Robot under maintenance" OutOfOrder = "Robot breakdown" END
Then, you will have the ability to read the associated value of an Enumeration variable via Value. // Access to the associated value e is RobotType RobotMessage is string = e..Value
The associated value has no incidence on the other behaviors of enumerations. Especially if the sort order is identical to the declaration order of values in the enumeration. Associated properties The following properties are associated with the Enumeration variables: | | Name | Allows you to find out the name of an Enumeration variable. | Value | Allows you to find out the associated value of an Enumeration variable. |
Available WLanguage functions An enumeration can be stored in an HFSQL item or in another file format. Depending on your needs, you can store the enumeration name or value ( Name or Value properties, respectively). The following WLanguage functions allow you to find out the characteristics of a stored enumeration:
Limits - The enumerations are not available in dynamic compilation.
- Enumerations cannot be used outside the project.
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|