Previous | Table of Contents | Next

Page 337

CHAPTER 14

Creating and Modifying
Master-Detail Forms

You can use the EMPCH14.FMB file on the CD to practice procedures discussed in this chapter.

Page 338

Adding Blocks to the Employee Update Form

In the previous chapters, the master block of the Employee Update form was created and formatted. The next step in the development of the form is to add detail blocks for the Tools table and the Glasses table. The Employee table used in the master block of the Employee Update form is related to the Tools and Glasses tables in a one-to-many relationship. Detail block tables are usually related to the master block tables in one-to-many relationships. Detail blocks usually contain many records for one record in the block.

Master blocks and detail blocks are joined together by using the primary key/foreign key. The primary key value in the master block is the value of the foreign key in the detail block. When creating the detail block, this relationship will be documented and become part of the form. Forms will create special form objects and triggers to programmatically retain this relationship. This is important functionality, because we want the records displayed in the detail block to pertain to the record in the master block.

Creating the Tools Detail Block

Detail blocks are created by using the same New Block Options dialog box shown in Chapter 12, "Using Object Navigator to Create Your First Oracle Form". We begin by following the procedure outlined in Chapter 12 to create default blocks. Perform the following steps:

  1. Select a block object and press the create button on the Object Navigator tool palette. The General tab of the New Block Options dialog box appears.

  2. Enter Tools in the Base Table field and TWO in the block name. Figure 14.1 shows the dialog box and settings.

FIG. 14.1
Naming the Base Table
and Block name of the
Tools detail block.




  1. Click the Items tab.

Page 339

  1. Click the Select Columns button to retrieve the Tools columns.

  2. Select each of the listed fields and modify the their labels.

  3. Click the Layout tab. This opens the Layout tab sheet. Figure 14.2 shows the Layout tab and the settings.

FIG. 14.2
Setting the number of
Records for the Tools
Block and adding a
ScrollBar.




  1. Change the number of records to 4 and click the scroll bar check box.

    If the block were a master block, you could click the OK button and create the block. However, this block is a detail block related to the Employee master block, which requires the Master/Detail tab sheet to be filled out. This sheet is shown in Figure 14.3. The sheet contains two items. The top item is the Master Block field, which contains the name of the master block. This is the block that will control the records that appear in the detail block.

  2. Enter ONE as the name of the master block. This is the name of the block on the Employee Update form created for the Employee table. The current record from this table will control the records in the detail block you are creating.

    The Join Condition window documents the join condition, which is one or more conditional statements that join the tables from the two blocks. This statement uses the same syntax used in joining tables by using a Select statement. The outer join option is not needed because Forms will always display the master record even if a corresponding detail record does not exist. The join condition in Figure 14.3 joins the blocks by using the payroll_number fields. Payroll_number is the primary key in the Employee table and a foreign key in the Tools table. When entering the join condition, you do not need to use the where keyword. You simply place the names of the join fields and the evaluation operator.

  3. Populate the Join Condition window with the following expression: "payroll_number = fk_payroll_number." Figure 14.3 shows the Master/Detail tab sheet and settings.

  4. Click the OK button to create the detail block called TWO. The block will be placed on the canvas. Figure 14.4 shows block TWO.

Block Coordination Objects and Settings

When a detail block is created, some special things occur. The first is that the join field(s) on the detail block are not displayed. In Figure 14.4, the fk_payroll_number field does not appear

Page 340

on block TWO because the field must always have the same value as the corresponding join value on the master block. Forms places the field on the block but sets the item's canvas property to null. This means the field can contain a value but does not appear on the form. Forms also places the name of the master block's join field in the detail block's Copy From property. This means the fk_payroll_number field on block TWO will copy its value from the payroll_number field on block ONE. This is an important feature in keeping the records in the two blocks in sync. Because the foreign key field (fk_payroll_number) on block TWO always has the value of the primary key on block ONE, block TWO will always display records that pertain to the record on block ONE. It cannot display records that apply to a different record.

FIG. 14.3
The Master/Detail tab
sheet and settings that
contains the join
condition to the master
block called ONE.




FIG. 14.4
The Employee Update
form after the detail
block TWO is created.




Forms creates several other Form objects that work to keep the blocks in sync. It creates a form-level trigger called On-Clear-Details. This trigger fires during coordination events and clears the records in the detail block. Forms also creates two block-level triggers on the master block. These are the On-Check-Delete-Master and On-Populate Details triggers. The former trigger fires during an attempt to delete a master record. This trigger determines whether children records exist for the record. If they do not exist, the record can be deleted. When they exist, an error message appears. The On-Populate Details trigger fires during the creation while the form is populating the block. It checks the status of the master record and the value of its primary key field. It then navigates to the detail block to issue the appropriate query.

Previous | Table of Contents | Next