Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Creating Custom Forms

Lesson A
Creating Custom Forms

Chapter Overview
This Chapter introduces creation of custom forms. In Forms Builder, a custom form, or control block
form, is built using the Layout Editor to manually place form items on the screen. Form behavior is
provided using command buttons and form triggers attached to those buttons. The form developer can also
code form navigation to control the way the user interacts with the form by setting tab order and making
form items read-only. Different canvas options including stacked and tab canvases are covered. Custom
form development can also be done using the Data Block Wizard and converting the data block created to a
control block. The Forms Debugger is also covered in this chapter. This is a full-featured debugging
environment including stack traces, variable watches, and breakpoints.

Lesson A

Lesson Objectives
 Learn about custom forms
 Create a custom form
 Create command buttons that use form triggers to manipulate data
 Use the Forms Debugger to find form logic and runtime errors
 Learn how form triggers work
 Create form navigation triggers

Introduction to Custom Forms


A custom form supports a business process rather than manipulating a particular database table. The form
contains fields that display data and command buttons to act on the data values. The buttons are linked to
form triggers that contain PL/SQL code. When building a custom form, the first step is to identify the
business process that the form supports. Then the user interface can be designed with all of the required
fields and buttons.

Creating a Custom Form


A custom form is created using the Layout Editor to place the fields and buttons on a canvas. The Object
Navigator is used to name the form items. The form is made up of one or more control data blocks, which
are like data form blocks but are not tied to one database table.

H.Seegobin 1
Creating Custom Forms
Lesson A
Creating the Form Canvas
Q1:
1. Create a new Form Module and name it RECEIVING_FORM and save the form
as 6AReceiving.fmb
2. Change the Window name to RECEIVING_WINDOW and change the window
title to Clearwater Traders.
3. Create a new Canvas and name it RECEIVING_CANVAS

Creating a Control Block


Q2:
1. Under the RECEIVING_FORM node, create a new DATA BLOCK and called it
RECEIVING_BLOCK. Select the Build a new data block manually option
button to create the above data block. Because you did not create the data block
using the Data Block Wizard and you have not associated the block with a
database table, it is a control block rather than a data block. You should see these
in the object navigator:

H.Seegobin 2
Creating Custom Forms
Lesson A

Creating the Form Items


Q3:
1. Double Click the icon next to the RECEIVING_CANVAS to open the Layout
Editor

2. The layout editor will be display as below:

3. Add a logo image, click Edit on the menu bar and point to Import, click the
Image, click Browse, and navigate to the picture that you want to insert as a logo
image.
4. Add a Label from the tool palette and called it “Process Incoming Shipment”.
Change the format of the Label as follows: Arial Font, Size 18.
5. Note: Change the Font Size back to Size 8 before you add any other items else all
the item created will be of size 18.

H.Seegobin 3
Creating Custom Forms
Lesson A
6. Add 7 Text Item and change their properties as follows:

Name Data Type Maximum Prompt


SHIP_ID Number 10 Shipment ID
INV_ID Number 10 Inventory ID
ITEM_DESC Char 100 Description
INV_SIZE Char 10 Size
COLOR Char 20 Color
SL_QUANTITY Number 4 Quantity
SL_DATE_RECEIVED Date 20 Date Received

7. Resize all the text item so that their width property value will be 100
8. To reposition the text item, select all of the text items as an object group, click
Layout on the menu bar, and then click Align Components. Select the Align Left
option button to specify the horizontal alignment, select the Stack option button
to specify the vertical alignment, and then click OK. Your Layout Editor will look
like below:

H.Seegobin 4
Creating Custom Forms
Lesson A
Creating the LOV
Q4:
1. Create an LOV based on the following query:
SELECT SHIP_ID, INVENTORY.INV_ID, ITEM_DESC, INV_SIZE,
COLOR, SL_QUANTITY
FROM SHIPMENT_LINE, INVENTORY, ITEM
WHERE SHIPMENT_LINE.INV_ID = INVENTORY.INV_ID
AND INVENTORY.ITEM_ID = ITEM.ITEM_ID
AND SL_DATE_RECEIVED IS NULL
2. Select all of the query fields for the LOV display, and then click Next. The
column Display Page appears.
3. Specify the following column display properties:

COLUMN TITLE WIDTH RETURN VALUE


SHIP_ID Shipment ID 45 RECEIVING_BLOCK.SHIP_ID
INV_ID Inv. ID 40 RECEIVING_BLOCK.INV_ID
ITEM_DESC Description 100 RECEIVING_BLOCK.ITEM_DESC
INV_SIZE Size 40 RECEIVING_BLOCK.INV_SIZE
COLOR Color 70 RECEIVING_BLOCK.COLOR
SL_QUANTITY Quantity 30 RECEIVING_BLOCK.SL_QUANTITY

4. Click Next. The LOV Display page appears. Type Expected Shipments for the
LOV title, change the width to 425 and then the Height to 150. Then click Next.
The Advanced Options Page appears.
5. Accept the default options and then click Next. The items page appears. This page
enables you to specify the form text item to which the LOV is assigned. You
assign the LOV to the SHIP_ID text item
6. Select the RECEIVING_BLOCK.SHIP_ID in the Return Items Lists, then click
the move one item to target button to move the selection to the Assigned Items
Lists. Click Next and then click Finish to finish the LOV.
7. Open the Object Navigator window, and change the name of the new LOV object
and record group object to SHIP_ID_LOV. Then save the Form and Run the
form. Make sure the insertion point is in the shipment ID text item, and then press
CTRL+L. The LOV displays open.
8. Select the Shipment ID 3 and Inventory ID 5 and then click OK. The selected
values appear in the form text items.

H.Seegobin 5
Creating Custom Forms
Lesson A
Displaying System Date and Time values in the Form Text Items
Q5:To display the current Operating System date in the text item:
1. Click Tools on the menu bar and then click Layout Editor. Select the
SL_DATE_RECEIVED text item, and then open the property palette of that text
item. Scroll down to the Data Property node and change the initial value property
to $$DATE$$.
2. Close the property palette. Save the Form and Run it.
3. The current system date now appears in the Date Received text item.

Forms Builder contains date and time system variables, which are useful for displaying the current date and
time in forms. The following table lists the date and time variables available in Forms Builder:

H.Seegobin 6
Creating Custom Forms
Lesson A
Creating Command Buttons
Command buttons are used to interact with a custom form to perform actions such as saving data. The
standard insert, delete and save buttons on the Forms Services toolbar are not available when working with
custom forms because the form is not tied to one table. Forms Builder does not generate the SQL code
necessary to make any changes to the form data. Therefore the forms developer must implement the
PL/SQL code to make changes to form data.

To create a command button the developer first draws the button onto the form canvas using the Layout
Editor's button tool. The developer can configure the button properties such as button label using the
Property Palette. The developer can then create form triggers for the WHEN-BUTTON-PRESSED
event to activate custom PL/SQL code when the button is pressed.

When creating the code for form triggers it is useful to break up tasks into the smallest logical units and
then to have the form trigger call one or more functions to achieve its result. For example, if both an
Update and Clear button clear the form, it makes sense to write a clear_form procedure that both form
triggers call rather than duplicating this code.

Q6:To Create the Form Buttons:


1. In the layout Editor, create 2 command button and change the following
property:
Name Label Width Height
UPDATE_BUTTON Update 60 16
CANCEL_BUTTON Cancel 60 16
The form will now look as below:

H.Seegobin 7
Creating Custom Forms
Lesson A
Q7:To Create the Update Button Trigger:
1. From Object Navigator, open the UPDATE_BUTTON node and select the
Triggers node, and then click the Create button to create a new trigger.
Select the WHEN-BUTTON-PRESSED event from the list. The PL/SQL
Editor opens
2. Type the following commands in the Editor and compile to see any mistakes
in the syntax:
--update the SHIPMENT_LINE records
UPDATE shipment_line
SET sl_quantity = :receiving_block.sl_quantity,
sl_date_received = :receiving_block.sl_date_received
WHERE ship_id = :receiving_block.ship_id
AND inv_id = :receiving_block.inv_id;
--update the INVENTORY INV_QOH value
UPDATE inventory
SET inv_qoh = inv_qoh + :receiving_block.sl_quantity
WHERE inv_id = :receiving_block.inv_id;
--commit the updates
COMMIT;
3. Save and compile the form.
4. Run the form, place the insertion point in the Shipment ID text item, press
CTRL+L to open the LOV display and select Shipment ID 2 and Inventory
ID 2. The shipment details appear in the Form.
5. Confirm that Quantity Received is 25 and Date Received is the current date
and then click Update.
6. What happens?
7. Check the value of the quantity in Shipment Line table and the QOH in the
Inventory. What did you noticed?

H.Seegobin 8
Creating Custom Forms
Lesson A
Creating a Program Unit to Clear the Form Fields in the Update Button
Trigger
Q8:To Create the Program Units:
1. Open the Object Navigator, select the Program Units node, and then click the
Create button to create a new program unit.
2. Type CLEAR_RECEIVING_FORM in the Name Field, make sure the Procedure
option button is selected, and then click OK. The PL/SQL Editor opens and displays
a heading template for the new program unit
3. type the following commands to add the program units commands:
PROCEDURE CLEAR_RECEIVING_FORM IS
BEGIN
:receiving_block.ship_id := '';
:receiving_block.inv_id := '';
:receiving_block.item_desc := '';
:receiving_block.inv_size := '';
:receiving_block.color := '';
:receiving_block.sl_quantity := '';
END;
4. Compile the program Unit, correct any Syntax errors and then close the PL/SQL
Editor.
Q9:To Modify the trigger to call the Program Units:
1. Open the PL/SQL Editor for the UPDATE_BUTTON.
2. Modify the trigger by adding the following command as the last line of the trigger
code:
CLEAR_RECEIVING_FORM;
3. Compile the trigger, then close the PL/SQL Editor and save the form.
4. Test the Program Unit by running the form.

Q10:To Create and test the Cancel button triggers:


1. Open the Layout Editor, select the Cancel button, right-click, point to
SmartTriggers, and then click WHEN-BUTTON-PRESSED. The PL/SQL
Editor opens for the new trigger.
2. Type the following command in the PL/SQL Editor:
CLEAR_RECEIVING_FORM;
3. Compile the trigger and then close the PL/SQL Editor.
4. Save and Run the form.
5. Test the Cancel button.

H.Seegobin 9
Creating Custom Forms
Lesson A
Directing Form External Navigation
External navigation of the form is any navigation caused by the user through clicking the mouse and using
the tab key. As the user navigates through the form, the form focus shifts to the currently selected item.
The form developer controls the external navigation by specifying a tab order for the fields and through
using BUILT-IN functions to move the form focus. The tab order is determined by the order of form items
in the Object Navigator.
Table 6-4 lists the BUILT-IN functions related to navigation:

Q11:To use the GO_ITEM built-in in the Cancel button Trigger:


1. In the Object Navigator, open the CANCEL_BUTTON node, open the Triggers
node, and then double-click the Trigger icon beside WHEN-BUTTON-
PRESSED to open the Cancel Button Trigger code. Add the following commands
as the last line of the trigger:
GO_ITEM(‘RECEIVING_BLOCK.SHIP_ID);
2. Compile the trigger, Close the PL/SQL Editor. Save and Run the Form.
3. Test your application. What do you noticed when you click on Cancel button after
displaying a record based on the LOV?

H.Seegobin 10

You might also like