4D v16.3

Field and variable objects

Home

 
4D v16.3
Field and variable objects

Field and variable objects  


 

 

In forms, fields and variables work in much the same way.

  • Fields are used to enter or display the data of a record. When you create a new form using the Form Wizard, you select the fields that you want to include in the form as standard objects. Once the form has been created, you can use the Form editor to specify additional properties such as the display format and data entry controls. These properties only apply to the forms in which they were specified. You can then use the same properties for other forms or specify new ones. You can change the properties of the fields or add/delete them at any time.
  • Variables can be enterable or non-enterable and can receive data of the Alpha, Text, number, Date, Time and/or Picture type. They are created in forms using the Variable tool . You can create a large number of variables automatically using the Duplicating on a matrix function.
    Like fields, variables let you enter and display data. Variables are used for temporary storage of data. One common use for a variable is to display calculations that are done using a method such as:
    vTotal := Quantity * Price
    You create a variable that displays the result of the calculation, name this variable vTotal, and use a method to do the calculation.
    You use methods to manage enterable and non-enterable variables. An enterable variable accepts data. You can set data entry controls for the object as you would for a field. The entered data is associated with the object name. You can manage the data with object or form methods using the object’s name as a variable.

You can also represent fields and variables in your forms in alternative forms, more particularly:

You can use the Variable Type property in the "Objects" theme of the Property List to specify the data type for the variable:

Note that main purpose of this setting is to configure the themes and options available in the Property list so that they will correspond to the data type. It does not actually type the variable itself. In view of database compilation, you must use the commands of the Compiler theme.

However, the Variable Type menu does have a typing function in two specific cases:

  • Picture variables: you can use this menu to declare the variables before loading the form in interpreted mode (see below)
  • Dynamic variables: you can use this menu to declare the type of dynamic variables (see Dynamic variables).

Specific native mechanisms govern the display of picture variables in forms. These mechanisms require greater precision when configuring variables: from now on, they must have already been declared before loading the form — i.e., even before the On Load form event — unlike other types of variables. 

To do this, you need:

  • Either for the statement C_PICTURE(varName) to have been executed before loading the form (typically, in the method calling the DIALOG command),
  • Or for the variable to have been typed at the form level using the Variable Type pop-up menu of the Property List.

Otherwise, the picture variable will not be displayed correctly (only in interpreted mode).

Display  

  • Variables and fields can be of any dimension. When they display characters, the size of the area varies in steps related to the font size of the characters used. Variables and fields can make use of display formats (see Display formats). Text and picture objects can use horizontal and vertical scroll bars (see Scroll bars) and can be printed with a variable frame (see ).
    Note: Text variables and fields in forms are designed to display contents of a "reasonable" size. Beyond several tens of thousands of characters (depending on the system), only part of the text will be accessible in the form.
  • When the Multi-style property has been checked for them, enterable variables and fields of the Text or Alpha type accept individual style variations (in addition to the general style specified at the object level). For more information, refer to GET DATA SOURCE LIST.

You can add or delete fields from a form at any time. For example, you may decide to add fields to a form when the following occurs :

  • You discover you need a field you did not choose in the Form Wizard.
  • You add a field to the database structure and need to add it to a form so that you can use it.

To add a field to a form:

  1. Select the field insertion tool   the toolbar then draw the field area in the form.
    4D automatically displays the properties of the new field in the Property List.
  2. Select the field you want to insert from the table/field list:

    Note: You cannot select a BLOB type field.
  3. If desired, select the specific properties you want to assign to the field.
    After creating the field, you generally need to set additional properties. You can set data entry controls, write help text, attach a method, set resizing or repositioning options, set font or appearance options (see Properties for active objects).
    Note: You can also insert a field by dragging and dropping it from the Tables Page of the Explorer.

The new field appears in the form where you placed it. The field area displays the name of the field you selected, preceded by the table name. By default, 4D does not add a label to designate the field but you can create one using a static text area. Note that the label itself can be defined dynamically (see Using references in static text).

After you place a field in a form, you can modify it as you would any other form object. You can resize it, change the font, choose colors for display on a color monitor, and so on.

You can transform every object type (active or not) into another object type. You can also transform a field into a variable and vice-versa. This is useful when, after inserting a field in a form, you want to change that field into a variable because you don’t need to store the value. When 4D changes an object into another object, it keeps the original properties of the object (coordinates, object method, appearance, color and so on. The data type assigned to a field will be kept for the variable: a picture field will be converted to a picture variable, and so on.

To change a variable into a field or a field into a variable, select the object and select Field or Variable from the Type drop-down list in the Property List (“Objects” theme). The Property List is then updated to display the properties for that new object type. The object name, object method, and its properties (size, enterable and so on) remain identical. 

When you change a variable into a field, 4D assigns the first field in the first table to the object by default. You can manually set the table and field in Source table and Source field (“Data Source” theme).

Save as  

When you associate a choice list with a field or variable, you can use the Save as Value/Reference option available in the "Data Source" theme of the Property List.

This option lets you optimize the size of the data saved. For more information, refer to Save as Value or Reference.

 
PROPERTIES 

Product: 4D
Theme: Working with active objects

 
HISTORY 

 
ARTICLE USAGE

4D Design Reference ( 4D v16)
4D Design Reference ( 4D v16.1)
4D Design Reference ( 4D v16.3)