Example 3: Making Each Form Even More Self-Contained

Each form will be made even more self-contained by adding activate and suspend functions to disable the F10 and Esc keys. Now the only way for the user to leave the form will be via the "Quit" pushbutton. The asymmetrical up/down behavior between fmp1 and fmp2 will be handled by setting the AUTOUPDN window option to request that the form automatically be brought down just before the call to the processing function returns. Another window option, AUTOFREE, will request that the form automatically be freed just before the call to the processing function returns. AUTOUPDN and AUTOFREE can be set for any object that can be made non-modal.

When using AUTOFREE, do not reference an object after you have exited or aborted it. The object is no longer in memory. If you are using the Vermont Views development libraries, you will receive a "Corrupted structure" error if you pass a pointer to this object to a Vermont Views function. If you are using the Vermont Views production libraries, this error will not be caught and memory corruption will occur.

The following code shows how to make each form even more self-contained:

#include <vv_mouse.h>

#include <vv_str.h>

#include <vv_date.h>

#include <vv_push.h>

#include <vv_des.h>

#include <vv_main.h>



int pb_save_form1(FORMPTR);

int pb_save_form2(FORMPTR);

int pb_quit(FORMPTR);

int activate(WINDOWPTR);

int suspend(WINDOWPTR);



#include "app3.h"



int main()

{

    FORM1 data1;

    FORM2 data2;

    DLIBPTR libp;

    DFORMPTR fmp1, fmp2;



    vv_init();

    if (libp = dl_open("app3.vvd"))

    {

        fmp1 = dl_fmget("form1", &data1, app3, NULLP, libp);

        userp_set(&data1, fmp1);

        fmp2 = dl_fmget("form2", &data2, app3, NULLP, libp);

        userp_set(&data2, fmp2);

        dl_close(libp);



        get_data_from_database(&data1, "Otterberg");

        get_data_from_database(&data2, "Sullivan");



        fm_up(fmp2);

        fm_proc(0, fmp1);

    }



    vv_exit();

    return(0);

}



int pb_save_form1(fmp)

DFORMPTR fmp;

{

    FORM1 *datap;



    fm_convert(fmp);

    datap = (FORM1 *) userp_get(fmp);



    write_data_to_database(datap);





    return(1);

}



int pb_save_form2(fmp)

DFORMPTR fmp;

{

    FORM2 *datap;



    fm_convert(fmp);

    datap = (FORM2 *) userp_get(fmp);



    write_data_to_database(datap);



    

    return(1);

}



int pb_quit(fmp)

DFORMPTR fmp;

{

    sfm_nextitem(AC_QUIT, fmp);

    sw_opt(AUTOUPDN | AUTOFREE, ON, fmp->wnp);

    return(1);

}



int activate(wnp)

WINDOWPTR wnp;

{

    /*------------------------------------------------------------------*/

    /* Disable the following keys            */

    /*------------------------------------------------------------------*/

    et_rplevnt(KEY_ESC, NULLFP, FLDETP);

    et_rplevnt(KEY_F10, NULLFP, FLDETP);

    et_rplevnt(KEY_ESC, NULLFP, PUSHETP);

    et_rplevnt(KEY_F10, NULLFP, PUSHETP);

    return(1);

}



int suspend(wnp)

WINDOWPTR wnp;

{

    /*------------------------------------------------------------------*/

    /*  Restore these keys to their defaults    */

    /*------------------------------------------------------------------*/

    et_rplevnt(KEY_ESC, kd_quit, FLDETP);

    et_rplevnt(KEY_F10, kd_exit, FLDETP);

    et_rplevnt(KEY_ESC, kd_quit, PUSHETP);

    et_rplevnt(KEY_F10, kd_exit, PUSHETP);

    return(1);

}

This last iteration has now made each form completely self-contained. This example could be extended to include non-modal menus, choice lists used as stand-alone menus, or windows used to view a memory file or memory screen.


Home Contents Previous Next