When you create a field, you specify, among other things, the field type and the field picture string. If you create the field in the Designer, the Designer automatically assigns a data variable of the appropriate type; if you create the field in code, you specify a variable of the appropriate type. These three items are related. The field picture determines what characters are allowed in the field, and the field type determines the type of the underlying data variable.
Designer: When you define a field in the Designer, you specify the field type and the field picture string. The Designer verifies that the picture string is consistent with the field type. When you generate a data structure for the form, the Designer places the correct type of data variable into the data structure.
Code: When you define a field in code with the field definition function, fld_def():
|
you specify a picture string (picp), the field type (fld_type), and a pointer to the data variable where you want the data to be stored (datap). All three must be consistent with the kind of data you want to collect from the field.
The data variable must be the appropriate type to store the information that the system reads from the field. For string, date, and time fields, the variable must point to an allocated memory block that is large enough to store the information gathered from the field.
Table 7.1: Data Field Basic Information
| Type of data
to be entered |
Field
Type |
Data type | Header File to #include | Allowed Picture Characters |
| Boolean value | F_BOOL | UCHAR | vv_bool.h | XA*!Z |
| Character | F_CHAR | UCHAR | vv_char.h | XA9#*!@ZU |
| Check box | F_CHECK | UCHAR | vv_check.h | XA*!Z |
| Date | F_DATE | UCHAR * | vv_date.h | 9UA*!X |
| Decimal numbers | F_DECIMAL | long | vv_dec.h | 9#@U |
| Floating point | ||||
| Single-precision | F_SINGLE | float | vv_singl.h | 9#AU |
| Double-precision | F_DOUBLE | double | vv_doubl.h | 9#AU |
| Integer | F_INT | int | vv_int.h | 9U |
| Long integer | F_LONG | long | vv_long.h | 9U |
| Short integer | F_SHORT | short | vv_short.h | 9U |
| String | F_STRING | UCHAR * | vv_str.h | XA9#*!@ZU |
| Time | F_TIME | UCHAR * | vv_time.h | 9UA*!X |
fld_def() expects a pointer to the underlying data variable for the field. For string-based field types (string, date, and time), specifying the name of the variable in the call is correct since variables for string data are defined in C as pointers. For other field types, you should precede the name of the variable with an & (ampersand) to convert it to a pointer. For example, the correct call for an integer field is as follows:
|
For maximum portability between operating systems and compilers, we recommend that you cast the pointer to type PTR as shown. The field definition function fld_def() is described in detail in Chapter 6, "Writing Forms in Code."
Caution: A string variable in C is, by definition, a pointer and you should not precede the names of string data variables with an & (ampersand) in fld_def(). String variables are used for string fields, date fields, and time fields.