What all this leads up to is that the following code fragment, which works correctly for modal forms, cannot work for non-modal forms.
int user_func(fmp)
DFORMPTR fmp;
{
DFORMPTR NonModalFmp;
DATA form_data;
DLIBPTR libp;
int ReturnVal = 0;
libp = dl_open("my_lib.vvd");
NonModalFmp = dl_fmget("my_form", &form_data, NULLP, NULLP, libp);
fm_up(NonModalFmp);
ReturnVal = fm_rd(0, NonModalFmp);
if (ReturnVal == AC_EXIT)
SaveDataToDatabase(form_data);
fm_dn(NonModalFmp);
fm_free(NonModalFmp);
return(TRUE);
}
This code fragment, small as it is, contains several serious non-modal errors:
nSpace for the form data is allocated off the stack. By the time the user can process this form, the variable form_data is out of scope.
nThe code does not check whether the form is already in memory. If it is already in memory, the call to dl_fmget() will create another copy of the form in memory.
nThe code does not check whether the form is already on the screen. If it is on the screen, the call to fm_up() will put another copy of the form on the screen, which will cause the user to think that any data that he previously entered in this form has mysteriously disappeared.
nThe code relies on the return value from fm_rd() to determine whether to save data into the database. If there is another processing function active, this call to fm_rd() will always return a value of AC_FMSUSPEND and data will never get saved to the database. If this is the only processing function active, that return value will apply to the last panel processed, which does not have to be NonModalFmp. The function may save data into the database even though the user quit from NonModalFmp.
nThe code takes the form off the screen before returning. If you are linking with the development libraries, this will be reported as an error when Vermont Views tries to move the user into NonModalFmp. If you are linking with production libraries, your program will fail.
nThe code frees NonModalFmp before returning, which means that the form is freed before the user ever gets a chance to enter data in it.