|
|
|
|
|
- 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
Enumeration and Combination items
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: - Create a new item in the description window of the data file items ("Description of items" in the context menu of the data file in the data model editor).
- Choose the "Enumeration, Combination" type.
- 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".
- 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. For more details, see The Enumeration type. Remark: 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: - Create a new item in the description window of the data file items ("Description of items" in the context menu of the data file in the data model editor).
- Choose the "Enumeration,Combination" type
- 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".
- 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. For more details, see The Combination type. Remark: 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 use items that must be transformed into Enumeration or Combination (to simplify code maintenance, to avoid assigning unwanted values, etc.), you can: - "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 or combination value in a non-HFSQL database (MySQL, Oracle, etc.) 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: - Add a new "Enumeration, Combination" item into the description of the desired data file (see previous paragraphs).
- 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.
- programmatically using HModifyStructure. Use this solution if you cannot access the data files (deployed applications for example).
- 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 option name is used as a value, use EnumerationFromName or CombinationFromName.
IF EnumerationCheckValue(EOrderStatus, Order.Status) THEN
Order.EnumStatus = EnumerationFromValue(EOrderStatus, Order.Status)
HModify(Order)
END
- Delete the former integer or string item.
- Rename (if necessary) the new item with the name of the former one.
Using an integer or string item You can also use an enumeration or 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:
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:
HReadFirst(Order)
eMyOrder is EOrderStatus
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).
eMyOrder is EOrderStatus
eMyOrder = WaitingForValidation
Order.OrderStatus= eMyOrder
To store the text of the option, you can use the Name property.
Order.OrderStatus= eMyOrder..Name
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|