Creating Custom Forms Chapter 6 A Guide to Oracle9i
Lesson A 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 A Guide to Oracle9i
Custom Forms • Display the data fields from a variety of database tables • Contain programs that support organizational processes • Not associated with one table • When creating custom forms: • Identify the processes that the form is intended to support, then identify the associated database tables. • Helpful to draw interface on paper A Guide to Oracle9i
Creating a Custom Form • Manually create the form canvas in the Object Navigator • Create the form items by “painting” the items on the canvas, using tools on the Layout Editor tool palette • Write the code that controls the form functions • Use a control data block • Not associated with one database table • Contains manually drawn form items • Controlled with form triggers A Guide to Oracle9i
System Date and Time Variables A Guide to Oracle9i
Creating Command Buttons • Create a command button by drawing the button on the canvas using the Button tool • Create button triggers manually for custom forms • Trigger fires on WHEN-BUTTON-PRESSED event • If multiple buttons execute similar actions (like clearing a form) create a separate program unit for this action A Guide to Oracle9i
Sample Button Trigger Commands A Guide to Oracle9i
Using the Forms Debugger to Find Runtime Errors • Use the Forms Debugger to find runtime errors that occur while a form is running • Identify the program line that is causing the error, and examine the variable values used within the command that has the error • Investigate the nature of the error by looking up the error code explanation • Error codes with the FRM- prefix are Forms Builder error codes • Error codes with the ORA- prefix are generated by the DBMS • Look up error code on otn.oracle.com A Guide to Oracle9i
Using the Forms Debugger • Click the Run Form Debug button on the Forms Builder toolbar • Set a breakpoint, which pauses execution on a specific program command • To debug: • Examine the current values of all program variables • Step through the program commands to observe the execution path • Examine variable values to see how the values change A Guide to Oracle9i
Setting a Breakpoint A Guide to Oracle9i
Forms Debug Console Windows A Guide to Oracle9i
Viewing Text Item Values A Guide to Oracle9i
Form Trigger Categories A Guide to Oracle9i
Trigger Properties • Trigger timing: • Specifies when a trigger fires • Can be just before, during, or after its triggering event • Before: PRE- • After: POST- • During: WHEN-, ON-, KEY- • Trigger scope • Defines where an event must occur in order for trigger to fire • Includes the object to which the trigger is attached, and contained objects A Guide to Oracle9i
Trigger Properties • Trigger execution hierarchy: • Defines which trigger fires when an object within a form object contains the same trigger that the form object contains • Can specify custom execution hierarchy A Guide to Oracle9i
Directing Form External Navigation • Form focus: currently selected item has form focus • External navigation: • Occurs when the user causes the form focus to change by making a different form item active • Internal navigation: • Occurs as a result of internal form code that responds to external navigation operations or trigger commands • Use external navigation to: • Specify initial form focus when form opens • Specify tab order A Guide to Oracle9i
Setting Tab Order in Object Navigator A Guide to Oracle9i
Directing External Navigation Using Built-in Subprograms A Guide to Oracle9i
Lesson B Objectives • Learn about default system messages and how to suppress them • Create alerts and messages to provide system feedback • Create applications that avoid user errors • Learn how to trap common runtime errors A Guide to Oracle9i
System Message Severity Levels A Guide to Oracle9i
Suppressing Messages • SYSTEM.MESSAGE_LEVEL: • Variable used to suppress error messages • Set to 0, 5, 10, 15, 20, 25 to suppress all messages with severity below this level • Default value is 0 • Set value in PRE-FORM trigger A Guide to Oracle9i
Providing System Feedback • Custom message: • A short text string displayed on the form message line • Use when the form needs to provide a short, simple message that does not require an acknowledgement from the user • To create: MESSAGE('message_string'); • Can be up to 200 characters A Guide to Oracle9i
Alerts • Dialog box that can display a longer text message • Displays one or more buttons that allow the user to select between alternatives that execute associated program statements • Use when: • Message is longer than 200 characters • User acknowledgement is required • User choice is required • See Figure 6-22 for example alert A Guide to Oracle9i
Displaying an Alert • In a form trigger: DECLARE alert_button NUMBER; BEGIN alert_button := SHOW_ALERT('alert_name'); END; • Use ELSIF structure to interpret and act on user response A Guide to Oracle9i
Avoiding User Errors • Forms should help users avoid errors by: • Validating input values • Programmatically disabling form command buttons • Disabling navigation for form text items containing values that users should not change A Guide to Oracle9i
Text Item Validation A Guide to Oracle9i
Form Validation Triggers • Item validation triggers: • Perform complex validations • Associate with WHEN-VALIDATE-ITEM event • Trigger code tests the current item value to determine if it satisfies the validation condition • If input not valid, form displays a message and raises a built-in exception named FORM_TRIGGER_FAILURE A Guide to Oracle9i
Disabling Form Command Buttons • Disable command buttons to prevent users from pressing them before form is in proper state • SET_ITEM_PROPERTY('UPDATE_BUTTON', ENABLED, PROPERTY_FALSE); A Guide to Oracle9i
Disabling Text Item Navigation • Prevent users from modifying primary key values • Make text item nonnavigable: • user cannot press the Tab key to place the insertion point in the text item • To prevent user clicking item: • Create a trigger that moves the insertion point to another form item whenever the user clicks the text item using the mouse A Guide to Oracle9i
Trapping Common Runtime Errors • Provide better error messages for common errors • Create form-level trigger for ON-ERROR event A Guide to Oracle9i
Syntax for ON-ERROR Trigger A Guide to Oracle9i
Lesson C Objectives • Convert data blocks to control blocks • Link data blocks to control blocks • Create a form that has multiple canvases • Create tab canvases • Create stacked canvases A Guide to Oracle9i
Converting a Data Block to a Control Block • Save time by creating a data block and converting to a control block • To convert data block to control block: • Change the data block’s Database Data Block property value to No • Change the Required property value of the text item that represents the data block table’s primary key to No A Guide to Oracle9i
Linking a Data Block to a Control Block • Useful in complex forms with master-detail relationships • Master is control block, details are data blocks • To link a control block with a data block: • Create the control block • Create the data block • Specify the link between the control block and the data block • Modify the form triggers to refresh the data block when the underlying data values change A Guide to Oracle9i
Control/Data Block Form Example A Guide to Oracle9i
Creating Forms with Multiple Canvases • Use multiple screens to avoid displaying too much information • Single-form approach: • Create one form with multiple canvases • Enables the form to share data among the different canvases • Impossible for multiple programmers to work simultaneously on different canvases of the same application • Multiple-form approach: • Create multiple forms with a different .fmb file for each application canvas • Works well when multiple programmers collaborate to create a complex application A Guide to Oracle9i
Viewing Canvas and Block Information A Guide to Oracle9i
Creating Multiple Canvas/Block Forms • Specify block and canvas ordering in Object Navigator • To navigate to another canvas programmatically, use GO_ITEM to navigate to an item on the canvas • Refer to items in triggers with syntax :block_name.item_name • Use caution to make sure items are placed in correct blocks A Guide to Oracle9i
Creating and Configuring Tab Canvases in Forms • Multiple-page canvases that allow users to move between multiple canvas surfaces by selecting tabs at the top of the canvas. • Use to: • Display a large number of related items in a modular way • Direct a user through a sequence of steps for performing a task • Lies on top of a content canvas within the form window. • Tab page: • An object representing a surface that displays form items • Has a tab label identifier at the top A Guide to Oracle9i
Creating a Tab Canvas • To create: • Create the form • Create a new content canvas in the form • Create a tab canvas on the content canvas • Configure the tab pages A Guide to Oracle9i
Creating a Tab Canvas A Guide to Oracle9i
Creating and Configuring Stacked Canvases in Forms • Lies on top of a content canvas • Use to hide canvas objects and then make the objects appear as needed • Create by: • Painting canvas in the desired position on an existing content canvas • Configure stacked canvas properties • Create the form items that are to appear • Write form triggers that contain commands to display the stacked canvas when it is needed and to hide the stacked canvas when it is not needed A Guide to Oracle9i
Configuring a Stacked Canvas A Guide to Oracle9i
Summary • Control blocks are created manually and do not represent data from only one table • Control blocks can be created from data blocks to make coding easier • Forms Debugger is used to find runtime errors in forms • User errors should be avoided by limiting opportunities for error • User feedback is presented in message line and alert boxes • A form may contain more than one canvas; canvases can be organized using tabs or shown and hidden programmatically A Guide to Oracle9i