Writing and Installing Begin- and End-Form Functions

Begin- and end-form 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        */

Your begin- or end-form function gets a pointer to the form currently being processed. From this form pointer, you have access to the data entered by the user in any item on the form, the status of the form, and the status of the items 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. For more details about these functions, see Chapter 34, "Getting and Updating Data in the Form."

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-form functions to your forms in the Designer, by selecting Modify->Current form->User functions and entering the name of the function to attach.

Code: To install a begin-form function for a form, call the set form begin function function, sfm_begfp():

void sfm_begfp(fmbeg_fp, dfmp)
 
int (*fmbeg_fp)();
/* Begin-form function pointer
*/
DFORMPTR dfmp;
/* Form to install function in
*/

To install an end-form function for a form, call the set form end function function, sfm_endfp():

void sfm_endfp(fmend_fp, dfmp)
 
int (*fmend_fp)();
/* End-form function pointer
*/
DFORMPTR dfmp;
/* Form to install function in
*/


Home Contents Previous Next