PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Overview
  • Creating Enumeration and Combination items in the data model editor
  • Creating an Enumeration item
  • Creating a Combination item
  • "Converting" an existing item to the Enumeration or Combination type
  • "Converting" an item into an Enumeration or Combination variable
  • Using an integer or string item
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Overview
WINDEV, WEBDEV and WINDEV Mobile propose the Enumeration and Combination types. The types are used to manage sets of values.
This help page explains:
Creating Enumeration and Combination items in the data model editor

Creating an Enumeration item

To create an Enumeration item:
  1. Create a new item in the description window of file items ("Description of items" from the popup menu of the data file in the data model editor).
  2. Choose the "Enumeration, Combination" type.
  3. In the "General" tab of the item description, click the button found on the right of the "Type" combo box and select "Create a new enumeration".
  1. The window for editing an enumeration is displayed:
    • Specify the enumeration name.
    • Add values ( button) or type the values in the table.
    • For each value, specify (if necessary) the associated value or the alias (an alias is an enumeration value that has the same value as another enumeration value but with a different name).
This enumeration can be used like any Enumeration variable defined in the code editor. See The Enumeration type for more details.
Note: If an Enumeration variable was defined in the code editor, to use this variable in an analysis item, this enumeration must be re-created in the data model editor.

Creating a Combination item

To create a Combination item:
  1. Create a new item in the description window of file items ("Description of items" from the popup menu of the data file in the data model editor).
  2. Choose the "Enumeration,Combination" type
  3. In the "General" tab of the item description, click the button found on the right of the "Type" combo box and select "Create a new combination".
  4. The window for editing a combination is displayed:
    • Specify the combination name.
    • Add values ( button) or type the values in the table.
    • For each value, specify (if necessary) the associated value or the alias.
This combination can be used like any Combination variable defined in the code editor. See The Combination type for more details.
Note: If a Combination variable was defined in the code editor, to use this variable in an analysis item, this combination must be re-created in the data model editor.
"Converting" an existing item to the Enumeration or Combination type
If your existing data files are using items that must be transformed into Enumeration or Combination (to simplify code maintenance, to avoid assigning unwanted values, etc.), you have the ability to:
  • "convert" the existing item into Enumeration or Combination variable. This solution is strict but it is complex to implement (especially if you have data files in production).
  • use an integer or string item to store the value or name of elements found in the enumeration or in the combination. This solution is easier to implement but it does not prevent from storing unwanted values. It can also be used to store an enumeration value or a combination value in a database not in HFSQL format (MySQL, Oracle, ...) where the Enumeration and Combination types are not available.

"Converting" an item into an Enumeration or Combination variable

The "conversion" must be performed in several steps:
  1. Add a new "Enumeration, Combination" item into the description of the requested data file (see previous paragraphs).
  2. Modify the physical data files. This modification can be done:
    • from the data model editor via the "Synchronization of Structure and Deployed Data". Use this solution if you can directly access the data files from the development computer.
    • by programming via HModifyStructure. Use this solution if you cannot access the data files (deployed applications for example).
  3. Fill the new Enumeration or Combination item from the content of source integer or string item. All you have to do is use EnumerationFromValue or CombinationFromValue. This function returns the option of enumeration or combination from a given value.
    Caution: a value must have been defined for each option of the enumeration or combination. If the name of the option represents the value, use EnumerationFromName or CombinationFromName.
    // If the Status item (integer) contains a valid value for the enumeration
    IF EnumerationCheckValue(EOrderStatus, Order.Status) THEN
    // Fills the Enumeration item with the corresponding value
    Order.EnumStatus = EnumerationFromValue(EOrderStatus, Order.Status)
    // Modifies the record
    HModify(Order)
    END
  4. Delete the former integer or string item.
  5. Rename (if necessary) the new item with the name of the former one.

Using an integer or string item

You also have the ability to use an enumeration or a combination without modifying your existing analysis. You can store the value or name of enumeration or combination option in an integer or string variable.
In this case, the conversions are performed during the read and write operations via the WLanguage functions.
For example, for the following enumeration:
// Enumeration with associated values
EOrderStatus is Enumeration
WaitingForValidation = 1
Prepared = 2
Shipped = 3
InDelivery = 4
Delivered = 5
END
The order status can be stored in an item whose type is:
  • integer: in this case, the value of the option (1, 2, ...) will be stored,
  • character string: in this case, the name of the option (WaitingForValidation, Prepared, ...) will be stored.
Caution: by default, if no value is explicitly defined for the options, the value of the option will be equivalent to its name.
To retrieve the enumeration or the combination from the item, use the following WLanguage functions:
For example:
// Reads the requested record
HReadFirst(Order)
// Defines an Enumeration variable
eMyOrder is EOrderStatus
// Retrieves the enumeration from the item
eMyOrder = EnumerationFromValue(EOrderStatus, Order.OrderStatus)
To assign an item from an enumeration or from a combination, you have the ability to directly specify the Enumeration or Combination variable. This allows you to directly assign the value defined for the option (equivalent to ..Value).
// Defines an Enumeration variable
eMyOrder is EOrderStatus
// Applies a value to the variable
eMyOrder = WaitingForValidation
// Assigns the Enumeration variable to the item
// Equivalent to Order.OrderStatus = eMyOrder..Value
Order.OrderStatus= eMyOrder
To store the option caption, you have the ability to use ..Name.
// Stores the name of the option in the item
Order.OrderStatus= eMyOrder..Name
Minimum required version
  • Version 20
This page is also available for…
Comments
Click [Add] to post a comment