Page 337
You can use the EMPCH14.FMB file on the CD to practice procedures discussed in this chapter.
Page 338
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.
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:
FIG. 14.1
Naming the Base Table
and Block name of the
Tools detail block.
Page 339
FIG. 14.2
Setting the number of
Records for the Tools
Block and adding a
ScrollBar.
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.