Customized Oracle Forms
Customized Oracle Forms
Custom forms do not contain data blocks that are associated with specific database tables.
Instead, they use SQL statements to manipulate data. These SQL statements are embedded in
triggers (form triggers that are different from the database triggers) that run when a user
performs an action such as clicking a button, e.g,. event. In a data block form, the triggers were
generated automatically when you created the data block. In a custom form, the person who
develops the form must write a trigger (an event procedure) for each button.
In this form, the INSERT button is used to insert a new record, the DELETE button is used to
delete an existing record, the SAVE button is used to modify an existing record, and the EXIT
button is used to exit the form.
The access key, Insert, Save, etc., can be created using &, e.g., &Insert in the property palette
(right-click the button).
Let's create a sequence object to insert the part number assuming the part number start with 10
incremented by 1 each time. Type this command at SQL*Plus prompt:
1
Customized Forms (Developer/2000) Oracle 9
SELECT partseq.nextval
INTO :part.text_partnum
FROM DUAL;
Compile the code (click the compile menu) Close if there is no error Save the form
Global Variables
This form has two states: INSERT and SAVE. We are going to use a global variable that
represents the current status of this form. Global variables provide a way to share information
among different triggers. They are referenced using the following general format:
:GLOBAL.variable_name, e.g., :GLOBAL.my_var := TO_CHAR(:order.total*.085);
• A global variable is an Oracle Forms variable whose value is accessible to triggers and
subprograms in any module that is active during the current session. A global variable stores
a character string of up to 255 characters in length.
• Global variables are not formally declared the way PL/SQL local variables are. Rather, you
initialize a global variable that the first time you assign a value to it:
• To reference a global variable, prefix the variable name with the word GLOBAL and a colon,
e.g., calculate_discount(TO_NUMBER(:GLOBAL.my_var));
• Referencing a global variable that has not been initialized through assignment causes a
runtime error.
• To destroy a global variable and release its memory, use the ERASE built-in procedure:
ERASE('GLOBAL.my_var');
EXIT_FORM;
Creating the EXIT button trigger:
In the 'WHEN-BUTTON-PRESSED' event, type the following code:
2
Customized Forms (Developer/2000) Oracle 9
In the Form Layout Editor, add a Push-button to the Part Number text item and change the
property of the button, 'Iconic' property to 'Yes', 'Iconfilename' to 'down'.
To Create a LOV object in the Object Navigator: Select LOVs and click add button (+)
change the name of LOV.
3
Customized Forms (Developer/2000) Oracle 9
DO_KEY(built-in-program);
DO_KEY executes the key trigger that corresponds to the specified built-in subprogram. If no
such key trigger exists, then the specified subprogram executes.
e.g., DO_KEY('LIST_VALUES');
LIST_VALUES(kwd);
Displays the list of values for the current item, as long as the input focus is in a text item that has
an attached LOV. The list of value remains displayed until the user dismisses the LOV or selects
a value.
☞ DO_KEY accepts built-in names only, not key names. To accept a specific key name, use the
EXECUTE_TRIGGER.
e.g.,
BEGIN
DO_KEY('Execute_Query'); -- simulate pressing the [Execute Query] key
END;
☞ When you initialize a Radio Group, set a radio button name to the radio group's value or
radio button's value to the radio group's initial value.
4
Customized Forms (Developer/2000) Oracle 9
To add a PRE-FORM trigger, Open the Object Navigator window right-click the Form
Module, and then click PL/SQL Editor Select the 'PRE-FORM' event (or Click the New
button on the PL/SQL Editor button bar and Select the 'PRE-FORM' event) click OK type
the following initialize statement and save the form:
:GLOBAL.mode := 'INSERT';
To create a Program Unit, Open the Object Navigator in Ownership view Click Program
Units Create button (+) type a procedure or function code.
You can shorten the Trigger code through using the Program Units.
Creating Alerts
To Create Alert objects in the Object Navigator Click Alerts Create button (+) Set the
properties of the Alert (right-click the Alert and change the properties).
To show Alerts, use the SHOW_ALERT function. For example, in the program unit
PROCEDURE DISPLAY_ALERTS IS
alert_button NUMBER; -- Alert number
BEGIN
alert_button := SHOW_ALERT('UPDATE_ALERT'); -- UPDATE_ALERT is the
-- alert name
IF alert_button = ALERT_BUTTON1 THEN -- user clicked OK
COMMIT;
alert_button := SHOW_ALERT('CONFIRM_ALERT');
CLEAR_FORM;
ELSE
ROLLBACK;
END IF;
END;
5
Customized Forms (Developer/2000) Oracle 9
Creating a Timer
TIMER_ID := CREATE_TIMER('timer_name', milliseconds, iterate);
splash_timer TIMER;
splash_timer := CREATE_TIMER('splash_timer', 5000, NO_REPEAT);
SHOW_WINDOW('window_name'); -- to show a window
As soon as user begins entering data in one of the items, the item is in Changed state, (initial
state before the user changes its item, is New). When user requests to commit the record, each
item and the record itself is set to Validated if validation is successful (no error).
Enter item validate item leave item: different state has corresponding triggers, e.g., Pre-
text-item-trigger, when-new-item-trigger ….
For more detail information about Developer/2000 and Oracle, Refer to Oracle
Online Help in the form window or Documents in http://www.ecs.fullerton.edu/oracle