How can I pass parameters between
FORMS?
|
More Resources by
Google: |
|
|
|
|
Gathered By:
John Kazerooni
Let’s suppose that you have two forms
named EMPLOYEES and DEPARTMENTS. In the EMPLOYEES form, if your cursor is pointing at the
“deptno” item when you click on a push button (“Show me department information…”) you
would want it to open a window to display all information about that department.
Step 1:
Create the “DEPARTMENT” form as you
create any other form.
Create a parameter and name it
p_deptno.
Open the parameter’s property palette and change the Parameter Data Type field to “Number,”
the Maximum Length field to “2,” and the Parameter Initial Value field to “10.”
Open the data block properties (DEPT)
and in the “WHERE Clause” property type deptno = :parameter.p_deptno
Create the “WHEN-NEW-FORM-INSTANCE”
triggers on form level and type “execute_query;” then compile the procedure.
Step 2:
Create the “EMPLOYEES” form as you
create any other form including the tabular, and 10 records at a time options, and check mark
“Display Scrollbar” option.
Create a control block and then create
a push button in that block. Open the push button’s property palette and change the “Name,”
and “Label” fields. The “label” value should be
“Show me department information…”
Create the “WHEN-BUTTON-PRESSED”
trigger and type the following code:
DECLARE
p_id paramList; -- This is a variable that
contains id of the parameter list
p_name VARCHAR2(20); -- A variable that keeps your parameter name
BEGIN
p_name := 'myparameter';
p_id := GET_PARAMETER_LIST('p_name'); -- find it if exists.
IF NOT ID_NULL (p_id) THEN
-- If exit then destroy it.
DESTROY_PARAMETER_LIST(p_id);
END IF;
--Now create a parameter list and add your p_deptno parameter.
p_id := CREATE_PARAMETER_LIST('p_name');
ADD_PARAMETER(p_id,'P_DEPTNO',TEXT_PARAMETER,to_char(:deptno));
--- You can call the called program either by default or specific like c:\folder\form.
OPEN_FORM('c:\DEPARTMENT',ACTIVATE,SESSION,p_id);
-- Error messages in case the called program was not able
-- to open called program.
IF NOT FORM_SUCCESS THEN
MESSAGE('ERROR: Unable to open the DEPARTMENT form.');
RAISE FORM_TRIGGER_FAILURE;
END IF;
EXCEPTION
WHEN others THEN
MESSAGE ('Error: unable to create parameter list…');
RAISE FORM_TRIGGER_FAILURE;
END;
Step 3:
Make sure that you have compiled the
DEPARTMENT form.
Step 4:
Now, you should be able to test.
Execute the query on the EMPLOYEES table and move your cursor to any record that you need to know
more information about its department. Then click on the “Show me department information” push
button. You should see complete information about that department.
Good Luck!
|