Tutorial for Designer/2000
and Developer/2000
Lesson 10
In this lesson, you will learn how to:
- Create Alerts (a modal window) on a push button that will function as a warning or a message to the users when they click the button.
- Create Procedures which are stored blocks of code which can be called from multiple objects saving the time taken for retyping codes
Creating an Alert
- Go to Alerts in the Object Navigator and double click on it. (See Figure 10.1)
Figure 10.1: Creating a New Alert
- Double click on the newly created alert and name it DELETE_ALERT. (See Figure 10.2)
Figure 10.2: Changing the name of the new Alert
- Now double click on the alert and you will immediately go to its Property Palette. In the properties:
- Change the title of the alert to Delete Alert
- Type in the message as "Are you sure you want to Delete?"
- Select Stop as the Alert style
- You can add a third button to the alert or just keep the OK and Cancel
- Make sure that Button1 is selected as the default button
(See Figure 10.3)
Figure 10.3: The Property Palette for the Alert
- To activate the alert, we will create a procedure which we will call from the delete button. To add a procedure, go to the Object Navigator and double click on Program Units. Immediately the window for the new Program unit will appear. (See Figure 10.4)
Figure 10.4: Creating a new Program Unit
- In the window for the new Program Unit, type in the name as Display_Delete-Alert. Make sure that procedure is selected as the type of Program Unit and click OK. (See Figure 10.5)
Figure 10.5: Naming the new Program Unit
- Once you click OK, you will be automatically taken to the PL/SQL Editor window. (See Figure 10.6)
Figure 10.6: The PL/SQL Editor window for the new Program Unit
- In the PL/SQL Editor, type in the following code for activating the alert. You may have to delete a couple of lines from the Editor to avoid duplication. In this code, we will declare a number variable called return_alert. We will then set it to show the alert that we created earlier in this lesson called Delete_Alert. We will then write a simple if/then statement, such that if the user clicks on OK, which is alert button 1, then Developer/2000 will perform the deletion and commit the changes. Otherwise, it will exit the alert window and help the users decide on their action. (See Figure 10.7 to get a view of the code as it should look in the PL/SQL editor. Do not forget to compile.)
PROCEDURE Display_Delete_Alert IS
return_alert NUMBER;
BEGIN
return_alert := show_alert ('DELETE_ALERT');
if return_alert = alert_button1 then
commit;
else
rollback;
end if;
END;
|
Figure 10.7: The code for activating the alert
- We will now add a push button to the form and then add the above procedure to it, so that whenever the user clicks on delete, the alert will be shown. To do this, go the Layout Editor and add a push button to the form, go its properties, andchange the label to Delete (use the steps used to create a push button in Lesson 9). Now go to its PL/SQL Editor by right clicking on the push button. (See Figure 10.8)
Figure 10.8: Selecting the PL/SQL Editor for the Delete button
- At the When-Button-Pressed trigger in the PL/SQL Editor, write the following code:
delete from student where studid = :studblock.studid;
delete_record;
Display_Delete_Alert;
|
The last line of the code will call the previously created procedure Display_Delete_Alert and activate the alert whenever the user clicks on the delete button. The first two lines of code delete the record for any particular student ID. (See Figure 10.9 to get a view of the alert when the user clicks the delete button).
Figure 10.9: The fully functional form with the alert on the Delete button
Lesson Summary
In this lesson you have learned how to:
- Create alerts on push buttons (delete) so that when the user clicks on the button the alert is shown as a warning
- Create procedures or stored blocks of code that can be called from any object
Next you will learn how to create reports. To do this, proceed to Lesson 11.
Back to the tutorial index.
Main Page
About the Book
Student Resources
Oracle Resources
Instructor Resources
Contact Us
©1999 Prentice-Hall, Inc., A division of Pearson Education, Upper Saddle River, New Jersey 07458 Legal Statement
Comments should be directed to webmaster@prenhall.com