Example 2: Making Each Form More Self Contained

You can improve on this first attempt by making each of the forms more self contained. One way to do this would be add a "Save" and "Quit" pushbutton to each form. Here is how the second cut at the application might look:

#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);



#include "app2.h"



int main()

{

    FORM1 data1;

    FORM2 data2;

    DLIBPTR libp;

    DFORMPTR fmp1, fmp2;



    vv_init();



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

    {

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

        userp_set(&data1, fmp1);

        fmp2 = dl_fmget("form2", &data2, app2, 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);

        fm_dn(fmp2);



        fm_free(fmp1);

        fm_free(fmp2);

    }



    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);

    return(1);

}

The above iteration is slightly better. The information is correctly saved to the database when the user selects the "Save" pushbutton. The forms are more self-contained. Operations from "main line" code are being removed and attached to pushbuttons. There is still the asymmetrical behavior when Esc or F10 is pressed. However, another problem has been introduced. The user can press F10 to exit the form, but the data will not be written to the database.


Home Contents Previous Next