Page 487
In the previous lesson, you became acquainted with Oracle Power Objects. You learned how to define a database session, how to create an application object, and how to create a simple form and a master-detail form. In this lesson, you continue exploring some of the features of Power Objects including the following:
Page 488
NEW TERM
A method is a set of instructions that are executed by an object in response to an event or a call to the object. Each type of object has a set of predefined methods called standard methods. The set of instructionswhich are Oracle Basic statementsexecuted for a method is known as method code. Some methods may have default processing that is executed if a developer has not written any method code.
The methods for an object are listed on the object's property sheet below the properties. On the property sheet, a small diamond is displayed to the left of each property, and a small arrowhead is displayed to the left of each method. Let's look at an example of a method for a form.
XPos.value = x YPos.value = y
Figure 18.1. Page 489
Method code for
MouseOver.
This script will assign the current x and y positions to the XPos and YPos fields, respectively. Click on the MouseOver method title to close the window. Alternatively, you can invoke the Code Editor window by clicking the Code Editor button at the top of the property sheet (it resembles a yellow pencil on a page). As you can see in Figure 18.2, the Code Editor window can be resized, making it convenient for entering a large block of method code.
Figure 18.2.
Using the Code Editor
window to specify the
method code for
MouseOver.
Close the property sheet and test the form by right-clicking Run Form. Figure 18.3 illustrates what your form should display in Run-Time mode.
Figure 18.3. Page 490
Testing the method
code for MouseOver.
Let's look at a commonly used method for a control: the Validate method. This method is used to enforce the business rules for an object. For example, suppose that one of the business rules for Flugle College is that the student ID must begin with a 1. To specify this business rule, select the Student_ID text field on the Student form, and bring up its property sheet. Scroll down to the Validate methodit's the last method for the object. Enter the Oracle Basic statements shown in Listing 18.1.
Listing 18.1. Enforcing a business rule in the method
code for Validate.
IF LEFT(newval,1) = "1" THEN Validate = TRUE ELSE Validate = FALSE MSGBOX("Student ID must begin with a 1" END IF
The business rule is expressed in the Oracle Basic statement, IF-THEN-ELSE. The first line uses the LEFT function to return the first character of the Student_ID being validated. If the first character is equal to 1, the Validate function will return TRUE, indicating that the new value passes validation; otherwise, the Validate function will return FALSE, preventing the user from navigating to another control or committing the change. Also, the MSGBOX function is used to display an error message to the user.
Let's test the method code.
Page 491
Figure 18.4.
Testing the method
code for Validate.
In the previous lesson, you learned how to display a lookup field that used the built-in function SQLLOOKUP. Now, you'll see how you can construct a field which will display a value that is calculated from the value of other controls in the form.
As an example, let's construct a form that displays information about each course.
RecSrcSession Flugle RecordSource Course OrderBy Department_ID, Course_ID Label Course Information Name CourseInformation
DataSource = Units.value*350 + Additional_Fees.value Datatype Long Integer Name Total_Cost
Page 492
Figure 18.5.
The CourseInforma-
tion form.
Figure 18.6.
Setting the
DataSource property
for the calculated
field.