ETI forms

Building a field type from two other field types

One way to define a new field type is to create one from two existing field types. The function link_fieldtype lets you do this.


   FIELDTYPE * link_fieldtype(type1,type2)
   FIELDTYPE * type1;
   FIELDTYPE * type2;
The constituent types may be system-defined or programmer-defined types. They may require additional arguments for the later call to set_field_type and may be associated with validation functions or choice functions. Validation functions validate the value in the field, while choice functions enable the user to choose the next or previous value of the field type. See ``Creating a field type with validation functions'' and ``Supporting next and previous choice functions''.

If additional arguments are required for the later call to set_field_type, those of type1 should precede those of type2. If there are validation or choice functions associated with the constituent types, the new type first executes the function associated with type1. If it is successful, it returns TRUE. If not, the new type executes the function associated with type2. Whatever it returns is the value returned by the new type.

As an example, the following code creates a new field type that accepts either a color keyword or an integer between 0 and 255, inclusive:

   FIELD *f1;

extern char ** colors;

ENUM_OR_INT = link_fieldtype (TYPE_ENUM, TYPE_INTEGER); /* Constituent types are System types described in "Setting the Field Type to Ensure Validation" */

set_field_type (f1, ENUM_OR_INT, colors, FALSE, FALSE, 0, 0L, 255L); /* create field of field type ENUM_OR_INT */

Once you have created the new field type, you can create fields of that type. The last statement here creates field f1, which accepts only values of type ENUM_OR_INT.

If an error occurs, link_fieldtype returns the following:

no available memory

Next topic: Creating a field type with validation functions
Previous topic: Creating and manipulating programmer-defined field types

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004