4D v13.4

Field and variable objects

Home

 
4D v13.4
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. 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 use the Variable Type property in the "Objects" theme of the Property List to specify the data type for the variable.
    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 transform a field into a variable and vice versa (see below).

Display  

  • Variables and fields can be of any size. 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 GET LIST ITEM PARAMETER). Text and picture objects can use horizontal and vertical scroll bars (see Scroll bars) and can be printed with a variable frame (see Printing text type objects).
  • 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 Multi-style (Rich text area).
  • URLs (strings starting with http, ftp, www or mailto) that are placed in fields or variables of the Text or Alpha type are detected automatically. If the user Ctrl+clicks (Windows) or Command+clicks (Mac OS) in the area, the URL is then executed directly in the default browser. Under Windows, detected URLs are shown in blue and underlined:

    Note:
    E-mail addresses must be written in the mailto:address form.

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).

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).

 
PROPERTIES 

Product: 4D
Theme: Working with active objects