ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / Editors / Data model editor / Logical Data Model
  • 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/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
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 the data file items ("Description of items" in the context 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".
    New enumeration
  4. The window for editing an enumeration is displayed:
    Edit an enumeration
    • 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:
  1. 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).
  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:
    Edit a combination
    • 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:
  1. Add a new "Enumeration, Combination" item into the description of the desired 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.
    • or by programming via the HModifyStructure WLanguage function . 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 option name is used as a value, use the WLanguage function EnumerationFromName or CombinationFromName.
    // Si la rubrique Etat (entier) contient une valeur valide pour l'énumération
    IF EnumerationCheckValue(EEtatCommande, Commande.Etat) THEN
    	// Remplit la rubrique Enumération avec la valeur correspondante
    	Commande.EtatEnum = EnumerationFromValue(EEtatCommande, Commande.Etat)
    	// Modifie l'enregistrement
    	HModify(Commande)
    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 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:
// Enumération avec valeurs associées
EEtatCommande is Enumeration
	EnAttenteValidation = 1
	EnPréparation = 2
	EnExpédition = 3
	EnLivraison = 4
	Livré = 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:
// Lit l'enregistrement voulu
HReadFirst(Commande)
// Définit une variable de type Enumération
eMaCommande is EEtatCommande
// Récupère l'énumération depuis la rubrique
eMaCommande = EnumerationFromValue(EEtatCommande, Commande.EtatCommande)
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).
// Définit une variable de type énumération
eMaCommande is EEtatCommande
// Applique une valeur à la variable
eMaCommande = EnAttenteValidation
// Affecte directement la rubrique avec la variable Enumération
// Equivalent à Commande.EtatCommande = eMaCommande.Valeur
Commande.EtatCommande = eMaCommande
To store the text of the option, you can use the Name property.
// Mémorise le nom de l'option dans la rubrique
Commande.EtatCommande = eMaCommande..Name
Minimum version required
  • Version 20
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 04/04/2024

Send a report | Local help