ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage syntax / Declaring variables
  • Declaring enumerations
  • Passing an enumeration as a parameter to a procedure
  • Special cases
  • Extensible enumerations
  • Creating aliases in an enumeration
  • Associated values
  • Associated properties
  • Available WLanguage functions
  • Limitations
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
An enumeration is a set of values. Only a value of an enumeration data set can be assigned to an Enumeration variable or parameter.
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
// Post1 = 1 // Displays a compilation error
// Post1 = "Walk" // Displays a compilation error
Syntax

Declaring an enumeration value Hide the details

<Enumeration name> is Enumeration
   <Enumeration values>
END
<Enumeration name>:
Name of the enumeration value to be declared
<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 the Enumeration variable to be declared.
<Enumeration name>:
Name of a previously declared enumeration. The default enumeration value corresponds to the first enumeration value.
Remarks

Declaring enumerations

An enumeration must be declared in:
  • The project initialization code so that it can be used in all the processes of the project (code of the project, windows, controls, procedures, etc.).
  • The global declaration code of a window so that it can be used in all the processes of the window (code of the window, controls in the window, local procedures, etc.).
  • The opening code of a report so that it can be used in all the processes of the report (code of the report, controls in the report, local procedures, etc.).
  • The class declaration code so that it can be used in the class.
    • To access this enumeration from a class method, use the following syntax:
      "::<Enumeration name>"
    • To access this enumeration from outside the class, use the following syntax:
      "<Class name>::<Enumeration name>"
  • The declaration code of a set of procedures so that it can 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: Assisted input for an enumeration-type parameter proposes the various enumeration values.
  • Order of values: The operators <, <=, >, >= are available on enumerations as well as automatic sorting operations (ArraySort, ArraySeek, ...). The order of the values in the enumeration is the order in which these 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

Extensible enumerations

You can include one or more values from other enumerations and add new values.
The following syntax is used:
<Enumeration name> is Enumeration
   [Base enumeration]
   <Additional enumeration values>
END
where:
  • Enumeration name: Name of a previously declared enumeration.
  • Base enumeration: Name of the base enumeration to be used.
  • Additional enumeration values: Additional values to 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
You cannot assign extension values in a base enumeration.

Creating aliases in an enumeration

You can declare aliases to ensure 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, you can associate a simple constant value 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, it is possible to read the value associated with an Enumeration variable using the Value property.
// Access to the associated value
e is RobotType
RobotMessage is string = e..Value
The associated value has no effect on other characteristics of the enumeration. For example, values are sorted in the same order as they were declared in the enumeration.

Associated properties

The following properties are associated with Enumeration variables:
NameGets the name of an Enumeration variable.
ValueGets the 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 can be used to get the characteristics of a stored enumeration:
EnumerationCheckNameChecks whether an enumeration value known by its name is valid.
EnumerationCheckValueChecks whether an enumeration value known by its associated value is valid.
EnumerationFromNameReturns an enumeration value known by its name.
EnumerationFromValueReturns an enumeration value known by its associated value.

Limitations

  • Enumerations are not available in dynamic compilation.
  • Enumerations cannot be used outside the project.
Minimum version required
  • Version 18
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 10/04/2024

Send a report | Local help