The application shown in the following illustration manages addresses using one window, Address_Maintenance, and one table, Address_Data. The key for the table is the Name field. (Remember that a table key is the field or group of fields used to sort and retrieve the record.) The illustration shows the form (represented by the black border), window, table and table buffer for the application.
When saving information from a window in a table, the user must first enter the information in the window, in this case, the address information for A-1 Construction. When all the information is entered, the user can click the Save button in the window to save the information in the table. The following script, attached to the Save button, performs two basic steps to save the information.
{Step 1: Copy the information from the window to the table buffer.} copy to table Address_Data; {Step 2: Save the information in the table buffer to the table.} save table Address_Data; {Clear the window to accept another record.} restart form;
The procedure is shown in the following illustration.
Retrieving a record is a multi-step process. The user must enter the key values for the record; in this case, the name A-1 Construction. Then the following script, a change script for the Name field, retrieves the record and copies the information to the window.
{Release the lock on any record currently in the table buffer.} release table Address_Data; {Step 1: Copy the key field from the window to the table buffer.} 'Name' of table Address_Data = 'Name' of window Address_Maintenance; {Step 2: Retrieve the record from the table, allowing the data to be changed.} change table Address_Data; {Step 3: Copy the information to the window.} copy from table Address_Data;
The change statement retrieves the record from the file, based upon the key value set in the table buffer. In this example, the record for A-1 Construction was retrieved because the key value was set to A-1 Construction. The copy from table statement copies the record from the table buffer to the window so the information is displayed.
To delete a record, the record must exist in the table and be retrieved using the “Retrieving a record procedure” just described. Then the record can be removed from the table. The following script, attached to the Delete button, will remove the record currently in the table buffer from the table.
{Remove the record currently in the table buffer from the table.} remove table Address_Data; {Clear the window to accept another record.} restart form;