A script-enabled browser is required for this page to function properly.

Opening Multiple Instances of the Same Form

It is common in multiple-form applications to allow end users to open multiple instances of the same form. This technique is useful for applications that allow end users to perform similar functions on different record sets, particularly when it is useful for each form to be managed within a separate transaction session.

When you programmatically open the same form n times, you have n instances of that form displayed on the screen and stored in memory. To refer to a specific instance of a form—by calling GO_FORM or CLOSE_FORM, for example—you must use the internal ID of the form instance (You cannot use the name of the form, since it is common to all instances of the same form.)

Once a form is open, use the Built-in function FIND_FORM to obtain its internal ID:

DECLARE
form_id FORMMODULE;
BEGIN
OPEN_FORM('stocks', no_activate);
form_id := FIND_FORM('stocks');
:GLOBAL.formid := TO_CHAR(form_id.id);
END;

In this example, a variable of type FormModule (a native Oracle Forms type) is declared. Once the STOCKS form is opened, its internal ID is assigned to the variable by the FIND_FORM function. The instance identifier then is converted to CHAR and assigned to a global variable.

Once stored in a global variable, you can retrieve the instance identifier at any time for operations on the specific form instance. The following example passes the instance identifier to the Built-in procedure GO_FORM:

DECLARE
form_id FORMMODULE;
BEGIN
form_id.id := TO_NUMBER(:GLOBAL.formid);
GO_FORM(form_id);
END;

The GO_FORM procedure takes a parameter of type FormModule, so the first step is to declare a variable of that type to hold the instance ID currently held in the global variable. Notice also that the instance identifier must be cast to NUMBER to be a valid FormModule value.

To store the instance identifier for several different forms, combine global variables with the COPY Built-in procedure:

DECLARE
form_id FORMMODULE;
temp CHAR(10);
BEGIN
-- Initialize a counter, open the STOCKS form, and
-- store its internal ID in form_id
--
DEFAULT_VALUE('1', 'GLOBAL.counter');
OPEN_FORM('stocks', NO_ACTIVATE);
form_id := FIND_FORM('stocks');
--
-- The COPY() procedure reads only global variables
-- and item values, so put the instance identifier in
-- in a a temporary global variable
--
:GLOBAL.temp_var := TO_CHAR(form_id.id);
--
-- Now assign the ID to the next occurrence of the global
-- variable :GLOBAL.form<x>, where x is the counter value
--
COPY(NAME_IN('GLOBAL.temp_var'),
'GLOBAL.form' || :GLOBAL.counter);
:GLOBAL.counter := TO_NUMBER(:GLOBAL.counter) +1;
END;

This example creates a set of global variables (:GLOBAL.form1, :GLOBAL.form2, etc.) which contain the instance identifiers for each open form. You then can use the appropriate variable for programmatic operations on a specific form.


FIND_FORM Built-in

Referencing Oracle Forms objects by internal ID