4D v14.3

Save as Value or Reference

Home

 
4D v14.3
Save as Value or Reference

Save as Value or Reference  


 

 

The Save as Value/Reference option is found in the "Data Source" theme for Field and variable objects as well as Pop-up Menus/Drop-down Lists:

This option specifies, in the context of a field or variable associated with a list of values (choice list), the type of contents to save in the field:

  • Save as Value (default option): the value of the item chosen in the list by the user is saved directly. For example, if the user chooses the value "Blue", then this value is saved in the field.
  • Save as Reference: the reference of the choice list item is saved in the object. This reference is the numeric value associated with each item either through the itemRef parameter of the APPEND TO LIST or SET LIST ITEM commands, or in the lists editor (see Adding a reference to an item).

This option lets you optimize memory usage: storing numeric values in fields uses less space than storing strings. It also makes it easier to translate applications: you just create multiple lists in different languages but with the same item references, then load the list based on the language of the application.

Using the Save as Reference option requires compliance with the following principles:

  • To be able to store the reference, the field or variable must be of the Number type (regardless of the type of value displayed in the list).
  • Valid and unique references must be associated with list items.
  • If you enable this option for a pop-up menu, it must be associated with a field (see Using a choice list).
  • This option is compatible with choice lists defined in the structure. In this case, you can just select the option in each form where the listed field is used.

Example  

You want to use a "Title" field to characterize people: Mr, Ms, but also Dr, Mgr, Hon, and so on. To do this, you create a longint type field named "Title". You define a choice list (named "Titles") containing all the possible titles, then you associate it with the field. 

In the input form, we show the "Title" field twice in order to illustrate the mechanism implemented: once as a pop-up and once as an entry area. Both objects are associated with the same choice list and the data is saved as a reference:

During input, you can select a value in the pop-up menu and it is displayed corrected in both objects:

Note: In this form, the "List" window is displayed when the entry area has the focus. If you no longer want to show this window, you can just use a pop-up menu for input and display of the values. (see Pop-up Menus/Drop-down Lists).

You can set up the output form on the same principle: you select the Reference option for saving the Title field:

During execution, the value is correctly displayed:

 
PROPERTIES 

Product: 4D
Theme: Properties for active objects

 
ARTICLE USAGE

4D Design Reference ( 4D v14 R2)
4D Design Reference ( 4D v14 R3)
4D Design Reference ( 4D v14.3)
4D Design Reference ( 4D v14 R4)