The following is the onClick event handler for a menu item that opens a customer form:

function View_Customer_onClick

   create session 

   do CUSTOMER.WFM 

By using the CREATE SESSION command, each customer form operates independently, as if they were being viewed by different people on different workstations. Navigation in one form does not affect the other. A record locked in one form will be respected by another form.

This example demonstrates some of the details of CREATE SESSION. Go to the Plus\Samples subdirectory. Select the Tables tab of the Navigator, and type the following statements in the Command window:

clear all && Release all variables and close all tables

create session && Nothing appears to happen

f = new Form()

use FISH && FISH appears in status bar, table is italicized in Navigator

create session && The status bar is cleared

use SAMPLES && SAMPLES appears in status bar, table is italicized in Navigator

This creates two worksets—call them WS1 and WS2 for reference. The order of the statements within each workset is irrelevant; they are simply executed in the currently active workset. The Fish table is the currently selected table in WS1 and the Samples table is the currently selected table in WS2. Form F is bound to WS1. WS2 has no forms bound to it, so its reference count is zero. The table names are now italic in the Navigator to indicate that they are open somewhere.

Now watch the italic Samples.dbf while you click the Navigator. Clicking the Navigator selected the startup workset. In switching worksets, the current workset, WS2, was checked. Its reference count was zero, so it was released, closing all the tables in it. Now click the Command window. This checks the Navigator’s workset, the startup workset. Its reference count is at least two for both the Command window and the Navigator, so it is never released. Now type:

f.alias = {; ? alias( )}

This attaches a codeblock to the form so that it becomes a method of the form. Now execute the method:

f.alias( ) && Displays FISH

? alias( ) && Blank, no table selected in startup workset

Executing a form’s method selects the form’s workset, where the Fish table is the currently selected table. After the method is complete, the previously active workset is reselected (note that there is no focus change here). Finally, watch the italic Fish.dbf in the Navigator as you execute:

release f

The variable is the only reference to the form (it’s not open on-screen), so the form is destroyed, reducing WS1’s reference count to zero, which releases WS1 and closes all the tables in it.