Vermont Views forms and most database management systems use C structures for their data. In most cases, these structures are not the same. To transfer data between these structures, you could create a begin-form function that takes the information from the database structure and feeds it into the Vermont Views structure. The form is then processed, and when complete, an end-form function could be used to feed the data back into the database structure so it may be updated. This method, however, is cumbersome and not recommended.
The solution to passing information between a Vermont Views structure and a database structure is to make both structures the same. If they are identical, then the information can be read directly from the database into the Vermont Views form and taken directly from the Vermont Views form and placed back into the database. No code is required to transfer the data.
There are provisions in Vermont Views to aid you in the situations where the structures are not the same:
| 1. | Your form has information on it that either comes from another database record or is not stored in that database at all.
In this case, you can set the field on the form to be OMITFROMSTRUCT. This means there will be no space in the data structure for it. Use sf_datap() to assign a data pointer to that field. |
| 2. | Your database record has information in it that is not used on the form.
In this case, you make a "dummy" field. This field exists on the form, but has its options set to PROTECTED and SKIP and its colors set to LNODISPLAY. With these settings, the field appears not to exist. |
For example, suppose the form appears as follows:
where name and phone come from the database and the date and time are the current system date and time. If the database uses an integer key for each record in the database, the database record would look as follows:
|
With no modifications, the two C structures would appear as:
| Vermont Views Structure | Database Structure |
|
|
|
|
|
|
|
|
|
|
|
|
|
Without using the two methods above, the name and phone number would have to be transferred from DBM_NAME_PHONE to VV_NAME_PHONE and back again with C routines:
|
This method, however, is a problem for a data form that has many fields. In this case, if we apply the two techniques discussed above, we would do the following:
| 1. | Add an integer field before the name field. Call the field "key." This field will be hidden from the user. To hide the field, set field option SKIP to ON for this field, and set the SKIP attribute for the field to LNODISPLAY. |
| 2. | For the date field, set the OMITFROMSTRUCT option ON. |
| 3. | For the time field, set the OMITFROMSTRUCT option ON. |
After following these steps, the Vermont Views structure would appear as follows:
|
The information can now be read out of the database directly into the database structure. That structure can then be passed to Vermont Views in the dl_fmget() call:
|
When the call to fm_proc() has been completed, the dbm_data data structure is already updated with the new values from the form. The dbm_data record can be written directly to the database.