Example 2 - Two windows and two tables

The application shown in the following illustration manages a list of customers using two windows, Customer_Maintenance and Comments. The Customer_Maintenance window is the main window for the form.

[spacer]

The application uses two tables, each with the following fields:

[spacer]

Customer_List

Customer ID

 

Name

 

Address

 

City

 

State

 

ZIP

 

Phone Number

Customer_Comments

Customer ID

 

Comments


The Customer ID field is the key for both tables.

Saving a record

When saving information from a window to a table, the user must first enter the information in the form’s windows. When all the information is entered, the user can click the Save button in the window to save the information to the tables.

To save information entered in windows into tables, the information must be copied from the windows to the appropriate table buffers. To simplify this process, Dexterity uses multiple table auto-copy. Multiple table auto-copy allows you to transfer all of the information from a table buffer to all the windows in the form using the copy from table statement, or from all windows in the form to the table buffer using the copy to table statement. Data will be copied between the corresponding window and table fields (those having the same resource ID).

The AutoCopy property for each window field controls whether the field will be updated by the copy from table and copy to table statements. By default, the AutoCopy property is set to true.

The copy to table statement must be used carefully when more than one window in the form contains the same table field. (In this example, the Name field from the Customer_List table is used for both the Customer_Maintenance and Comments windows.) The copy to table statement will copy the fields from the main window to the table buffer, then copy fields from any child windows (windows in the form other than the main window) to the table buffer. This means the contents of the common field in the child window will be copied to the table buffer, replacing any values copied from the field on the main window. This will occur even if the child window isn’t open.

To prevent storing fields with empty or incorrect information in a table, be sure that all common window fields have the same value before using the copy to table statement. Another solution is to use the copy from window to table statement, which copies information from only the specified window to the specified table buffer.

The following script, attached to the Save button, performs the steps necessary to save the information. The illustration on the following page shows each step.

{Step 1: Because the Name field appears on both the Customer_Maintenance and Comments windows, the Name field in the Comments window is set to the value of the Name field in the Customer_Maintenance window. This will ensure that the correct value will be saved to the Customer_List table.}
'Name' of window Comments = 'Name' of window Customer_Maintenance;

{Step 2: Copy the information from the windows to the Customer_List table buffer.}
copy to table Customer_List;

{Step 3: Save the information in the Customer_List table.}
save table Customer_List;

{Step 4: Copy the information from the windows to the Customer_Comments table buffer.}
copy to table Customer_Comments;

{Step 5: Save the information in the Customer_Comments table.}
save table Customer_Comments;
restart form;

The procedure is shown in the following illustrations. The customer record for April Berger is entered, then saved.

[spacer]

[spacer]

Retrieving a record

Retrieving a record is a multi-step process. The user must enter the key values for the record; in this case, the Customer Number 104 for April Berger. Then the following script, a change script for the Customer ID field, retrieves the correct records from the Customer_List table and the Customer_Comments Table and copies the information to the Customer_Maintenance and Comments windows.

{Release the lock on any record currently in the Customer_List table buffer.}
release table Customer_List;

{Step 1: Copy the key field from the window to the Customer_List table buffer.}
'Customer ID' of table Customer_List = 'Customer ID' of window Customer_Maintenance;

{Step 2: Retrieve the record from the Customer_List table, allowing the data to be changed.}
change table Customer_List;

{Step 3: Copy the information from the Customer_List table buffer to the windows so it is displayed.}
copy from table Customer_List;

{Release the lock on any record currently in the Customer_Comments table buffer.}
	release table Customer_Comments;

{Step 4: Copy the key field from the window to the Customer_Comments table buffer.}
'Customer ID' of table Customer_Comments = 'Customer ID' of window Customer_Maintenance;

{Step 5: Retrieve the record from the Customer_Comments table, allowing the data to be changed.}
change table Customer_Comments;

{Step 6: Copy the information from the Customer_Comments table buffer to the window so it is displayed.}
copy from table Customer_Comments;

The procedure is shown in the following illustrations.

[spacer]

[spacer]

[spacer]

[spacer]

Deleting a record

To delete a record, the record must exist in the table and be retrieved as described in the previous section. Then the record can be removed from the table. The following script, attached to the Delete button, will remove the records for the current customer from the Customer_List and Customer_Comments tables.

{Remove the record currently in the Customer_List table buffer.}
remove table Customer_List;
{Remove the record currently in the Customer_Comments table buffer.}
remove table Customer_Comments;
{Clear the windows to accept another record.}
restart form;


Documentation Feedback