Reference examples

This section describes two ways references can be used in application development.

Example 1

This example describes how to create and use a reference to a table buffer. Main Table is a local field using the Reference control type. It has been added as a hidden field in the Sellers window. The Main Table field will store a reference to a table. The SavedOnRestart property is set to true to ensure the reference value isn’t lost when the form or window is restarted.

[spacer]

The following is the form pre script for the Sellers form. It creates a reference to the Seller_Data table and stores it in the Main Table reference field.

assign 'Main Table' of window Sellers as reference to table Seller_Data;

The following is the script for one of the browse buttons in the Sellers window. This script is generic, meaning that it has no knowledge of what table it is retrieving data from. It simply retrieves the first record in the table buffer referred to by the (L) Main Table variable. Then it copies the contents of the table buffer to the window.

{Retrieve the first record from the referenced table and display it.}
change first table('(L) Main Table');
copy from table('(L) Main Table');

Example 2

This example describes how to create and use a reference to a window field. A global reference field named Status Reference has been created for the application and defined as a global variable.

The following is the form pre script for the Main Menu form. It creates a reference to a status field in the Toolbar window that is part of the Main Menu form.

assign 'Status Reference' of globals as reference to field 'Status' of window Toolbar of form 'Main Menu';

Any procedures that need to display status information can use the field indicated by the Status Reference global variable. For example, the following statement sets the status to “Finished”.

field('Status Reference' of globals) = "Finished";

This statement has no knowledge of where it is setting status information. It is simply sets the field referred to by the Status Reference global variable.

 


Documentation Feedback