Writing and Installing Begin- and End-Field Functions

Begin- and end-field functions take a pointer to the current form and return an integer. The call is as follows:

int usr_func(dfmp)

DFORMPTR dfmp;        /* Form being processed        */

The form editor passes the pointer to the form currently being processed. From this form pointer, you have access to the data entered by the user in the current field, the status of the current field, and information about any other item or field on the form. You can get the pointer to any item on the form and make changes in the options or settings of the item. Functions are also provided to indicate to the editor what item you want to move to next and to set the next action code.

Your function should return TRUE on success and FALSE on failure. A return value of FALSE causes form processing to terminate immediately. In this case, the high-level processing function (fm_proc() or fm_rd()) will also make an immediate error return. You should reserve a FALSE return for unrecoverable errors.

To quit processing the form without saving the data that the user has entered, you can call sfm_nextitem() with the action code AC_QUIT. To exit from the form and save the data, you can call sfm_nextitem() with the action code AC_EXIT.

If your function fails, you can set the global error code VV_ERR to provide more information about the error to higher-level routines. You can use the existing error codes or add your own error codes and messages. See Chapter 50, "Debugging and Error Handling," for instructions on adding more error codes and error messages.

Designer: You can attach begin- and end-field functions to your forms in the Designer, by selecting MODIFY->Field->User functions and entering the name of the function to attach.

Code: To install a begin-field function for a data field, memo field, or a field in a scrollable region, call the set begin field function function sf_begfp():

void sf_begfp(fldbeg_fp, memo_or_fldp)
 
int (*fldbeg_fp)();
/* Begin-field function pointer
*/
FIELDPTR memo_or_fldp;
/* Field to install function in
*/

To install an end-field function for a data field, memo field, or field in a scrollable region, call the set end field function function sf_endfp():

void sf_endfp(fldend_fp, memo_or_fldp)
 
int (*fldend_fp)();
/* End-field function pointer
*/
FIELDPTR memo_or_fldp;
/* Field to install function in
*/


Home Contents Previous Next