IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
Paradox
Search Paradox Group:

Advanced
-Collapse +Expand Paradox To/From
To/FromCODEGuides
-Collapse +Expand Paradox Store
PRESTWOODSTORE

Prestwood eMagazine

October Edition
Subscribe now! It's Free!
Enter your email:

   ► KBDesktop Data...Paradox & Ob...ObjectPAL Co...OPAL: Langua...   Print This     
 
Paradox OPAL: Language Basics:
An ObjectPAL Primer: Part 2
 
Posted 21 years ago on 3/18/2003 and updated 6/19/2008
Part 2.
 Tags: Paradox , ObjectPAL , primer

KB100164

The Elements of ObjectPAL

Now that you have gotten your feet wet, take a closer look at ObjectPAL. ObjectPAL consists of many different elements. When you study a broad subject such as a programming language, it often is helpful to categorize what you are about to learn. The following paragraphs describe the elements of ObjectPAL.

An event handler is a type of programming language that has preset triggers to which the programmer can attach code. The idea of attaching code to triggers on objects puts Paradox in this category. Do not confuse the category of event handler with the term event model. An event model is the map that an event handler uses to process events. The events are the triggers that start your code, such as pushButton, open, and changeValue. Events are part of the event handler.

The actual words or building blocks of ObjectPAL are called keywords, such as doDefault, DisableDefault, method, endMethod, var, endVar, if, endIf, switch, and endSwitch. For example, an if statement is comprised of the following keywords: if, then, the optional else, and endIf. The ObjectPAL editor displays all keywords in bold. Consider keywords to be the skeleton of your code.

The methods--commands--act on and belong to objects, such as open(), setPosition(), and moveTo(). Examples of methods include formVariable.open("form"), theBox.setPosition(100,100), and fieldName.moveTo(). Methods differ from procedures, which are commands that don't have a specified object on which they work, such as close(), setTitle(), and setAliasPath(). Examples of procedures include close(), setTitle("My Application"), and setAliasPath("MyAlias", "C:\\WORK\\DATA").

In ObjectPAL, you can manipulate the properties--the characteristics--of objects, such as value, color, and tabStop. Examples of properties include fieldName.value = "Angie Herbal", theBox.frame.color = Blue, and buttonName.tabStop = True. Most of the properties that you set interactively by typing in values or inspecting an object can be set using ObjectPAL.

Object variables are built into the language, such as self, container, and active. Examples of using object variables include self.color = Red, container.color = Blue, and message(active.Name).

A constant is a word that represents an unchanging value you can use in ObjectPAL. ObjectPaL has both predifined constants and user defined constants. Red, DataInsertRecord, and True are all constants that ObjectPAL already understands. With constants, the number the constant represents does not matter (and can change in a future version). This humanizes ObjectPAL; that is, it makes it easier to relate to. You use a meaningful word rather than a number in your code. Examples of using constants include box1.color = Red, action(DataInsertRecord), and fld3.tabStop = True. You also can use user-created constants; more on constants you create later in the section titled "Basic Language Elements and ObjectPAL."

Introducing the Event Handler

In the first example earlier in this chapter, you used the pushButton event of a button, but how do you know which event to add code to? One thing that makes ObjectPAL easy to learn is that it is an event-driven language. You can refer to the event-driven part of ObjectPAL as the event handler. In a traditional procedural language, you have to write everything, including the interface--one of the least favorite tasks for a developer.

In Paradox, you design the interface interactively with little trouble. In fact, it's fun to design forms with Paradox. With the interface out of the way, you simply attach code to enhance or restrict the interface and its built-in behavior. In most cases, you want to put the code on the object on which you want it to act. If you want a button to do something, put code on the pushButton event of the button. If you want to prevent a user from leaving a field, put code on the canDepart event of that field. Whenever you search for a place to put code, ask yourself, "What object am I working with or on?" Think of programming in ObjectPAL as attaching small bits of code to events or triggers. Table 4-1 lists some common events you can place code in. This table can be valuable for beginning ObjectPAL programmers.

Object

Location

Example of Typical Use

Form

init

Initializes variables and set up tables

Form

arrive

Maximizes a form and sets values in the form

Form

menuAction

Processes menu events

Form

action

Traps for key violations on a single table form

Form

mouseExit

Clears the status bar if you use mouseEnter

Page

arrive

Sets up a custom pull-down menu

Button

pushButton

Executes code when the user selects a button

Button

mouseEnter

Adds help by sending a message to the status bar

Field

changeValue

Checks a new value against an old value in a table

Table 1: Common Places to Put Code

Every object has a default behavior that you can modify with built-in events. Most objects share the same built-in events: action, menuAction, arrive, canDepart, mouseClick, and error. Some objects have unique built-in events, such as pushButton for a button.

The Six Beginner-Level Events

Whenever you're looking for a place to put code, consider ObjectPAL's six beginner-level events first. These core events are the events new users to ObjectPAL will use most. Table 4-2 provides a short description of each.

Method

Description

action

Used when a user calls, or triggers, an event. Typically, action is used for trapping events and processing them. For example, action is useful for trapping database actions such as inserting a record, and moving in and out of edit mode.

menuAction

Called whenever a user selects a menu option. Put code in the menuAction method if you wish to trap for when the user selects an option from the menu, toolbar, or form control box.

arrive

arrive occurs whenever focus moves to a field. At first, arrive seems identical to setFocus, which occurs whenever focus moves to an object (and with fields, this appearance is somewhat accurate). With some objects, however, it is not. Look at a form opening to illustrate. First, the init event is called, followed by open and arrive, and finally setFocus. arrive occurs only after open, whereas setFocus occurs whenever the form becomes active--for example, with a multiple form application. You can use arrive to instruct the user what to enter. By the way, arrive only occurs after canArrive.

canDepart

Think of canDepart as the opposite of arrive. Typically, canDepart is used for data integrity. For example, if the value is less than 100, canDepart can prevent the user from leaving the field until the correct value is entered.

mouseClick

This is triggered whenever the logical left mouse button is pressed and released when the mouse is on an object.

error

This event is triggered whenever an error occurs. The error event is used to add to the event action (response).

Table 2: The Six Beginner-Level Events

Types of Commands

ObjectPAL has several types of commands you can use in an event. This section addresses procedures, methods, keywords, and properties, which are some of the commands you can use in an event.

Identifying Procedures

You already have used a procedure in your first example. A procedure is a powerful type of command; it can stand alone. In other words, a procedure would be complete on a line by itself. For example, each of the following is a procedure.

1:    message("Press OK to continue")
2:    msgInfo("Warning", "You are about to delete a record")
3:    isFile("C:\\DOS\\COMMAND.COM") ;Note the double \.

Identifying Methods

A method is a weaker type of command. You must use an object of the same type as its class when using a method. For example:

1:    TaxableField.isBlank()   ;TaxableField is a Field object.
2:    f.open("FORM1")          ;f is a Form object.

Another way to look at methods versus procedures is to say that a procedure always knows the object it works on or with, but a method does not. To further confuse the issue, some commands can serve as both procedures and methods, as in the following example:

1:    close()     ;Procedure that closes the current form.
2:    f.close()   ;A method that closes the form associated
3:                ;with f (f is a form variable).

Line 1 uses the close() command as a procedure--it knows to close the current form. If, however, you use close() as a method, you need to specify an object. In line 2, f is a form variable you have opened previously.

The Alternative Syntax

Do not confuse a command that can be both a method and procedure with the alternate syntax. Whenever you code object.method(), the alternate syntax enables you to code method(object), as in the following example:

f.close()   ;Regular syntax.
close(f)    ;Alternate syntax.

When a single command supports the alternate syntax, which syntax should you use? Although it doesn't really matter, the regular syntax object.doIt(), as seen in the preceding first line, is preferred. It's more consistent with the rest of the language. Don't worry too much about these variations in syntax at this point.

Identifying Keywords

Keywords are words reserved for use with certain commands in ObjectPAL. They are special language construct commands that are neither procedures nor methods. Keywords include Proc, endProc, method, endMethod, doDefault, iif, and Database. At this point, just be aware that you shouldn't use keywords in ObjectPAL for the names of objects or variables.

Following is an example of keywords that are used properly:

1:    ;Button :: pushButton
2:    method pushButton(var eventInfo Event) ;method is a keyword.
3:       if taxable.value = "Yes" then       ;if & then are keywords.
4:          tax.value = subtotal * .06
5:       else                                ;else is a keyword.
6:          tax.value = 0
7:       endIf                               ;endIf is a keyword.
8:    endMethod                              ;endMethod is a keyword.

method, if, then, else, endIf, and endMethod are all keywords. You can't give objects or variables names that are the same as these keywords. In fact, it's a good idea not to give an object or a variable the same name as any element of the ObjectPAL language.

Altering Properties and Dot Notation

Objects that you place on a form have properties. You have already set many of the properties of objects--for example, when you change the color of a box on a form to blue. With ObjectPAL, you can alter an object's property with dot notation. Dot notation is the basic syntax structure used in ObjectPAL. It uses dots to separate elements in a complex statement. Following is the basic syntax structure:

ObjectName.property = Constant

The capability to alter properties while the form is running is powerful and sets Paradox above many other DBMS systems. Following are some examples of altering the properties of objects:

1:    box1.color = Blue             ;Change box1 to blue.
2:    box1.visible = False          ;Make box1 disappear.
3:    Last_Name.color = Yellow      ;Change field color.
4:    City.tabStop = False          ;Do not allow focus to City.

Dot notation also can represent a complete path to an object. The following examples set the properties of objects in other objects:

1:    pge3.box1.Last_Name.color = DarkGray    ;Change field to dark gray.
2:    f.pge3.visible = False                      ;Make a page disappear.
3:    box1.Last_Name.Frame.Style = Windows3DGroup ;Change the style. 

The example in line 3 of the preceding code represents a compound property. The path of the object is box1.Last_Name. The compound property is Frame.Style. This is confusing, especially when learning ObjectPAL. For now, understand that both the object path and the property can be composed of multiple values. The following are three instances for which dot notation is used in ObjectPAL:

To separate an object and property, as in the following:

Last_Name.value = "Santwier"

To separate or indicate an object's path, as in the following:

pge2.boxSection3.Last_Name.value = "Santwier"

To separate an object and a method, as in the following:

Last_Name.moveTo()

Note: For now, think of the containership path of an object as analogous to a directory path. When you open a file, you specify its path--for example, C:\PDOXWIN\DATA\MYFORM.FSL. You can think of a subfolder as being owned (or contained) within its parent folder just as objects are owned (contained) by owner objects. When referring to objects, you need to specify the path of the object with dots rather than a slash, as in the following example:

pge2.boxSection3.Last_Name.

Properties are another type of code you can use in ObjectPAL to get or alter the attributes of an object. Think of objects as having a set of properties attached to them. Some of the properties of a field object are value, color, font.color, TabStop, Name, FieldName, TableName and Enabled. The next example demonstrates that you can alter the properties of objects with ObjectPAL.

Changing the Color of a Box

Suppose that you want to change the color of a box when the user clicks the box. This example uses the mouseClick method of a box to alter the property color. The object variable self is used to refer to the object to which the code is attached. This example also demonstrates using dot notation.

On The Net: http://prestwood.com/forums/paradox/books/official/files/COLOR.FSL.

Step By Step

1.        Create a new form and add a box to the form (see Figure 4-7).

Figure 7: Setup form for example

2.     Right-click the box and select Object Explorer to display its Object Explorer.

3.     Select Events.

4.     Open the built-in mouseClick method.

In the mouseClick method, enter lines 3 and 4. Lines 2 and 5 begin and end the method attached to the event. These lines of code are always provided for you by ObjectPAL. In line 2, note that the eventInfo variable type in this case is MouseEvent. This is important to note and is discussed in more detail later. For now, understand an event of type MouseEvent was sent to the mouseClick event. Line 3 is a comment. Lines that start with a semicolon are stripped out when the form is compiled or run. Do yourself a favor and comment all your code heavily. You'll appreciate your efforts when you go back to the code a month later. The semicolon also is a good way to disable a line of code; it's useful when you debug code. Look at line 4, which uses a special built-in object variable, self, to refer to the object to which the code is attached. If you named the box box1, you could have used box1.color = Red rather than self.color = Red. color is a property of the object type Box; in this case, we set it to red.

1:    ;COLOR :: theBox :: mouseClick
2:    method mouseClick(var eventInfo MouseEvent)
3:       ;The following changes the color of self.
4:       self.color = Red
5:    endMethod 

Check your syntax and save the form as COLOR.FSL.

Close the Edit box and run the form by selecting View | View Data. Click the box and watch the color change. The completed form is shown here:

One type of code that you write in ObjectPAL gets or alters the property of an object. Think of objects as having both attributes (properties) and code (methods and procedures) attached to them. Some of the properties of a field object are value, color, tabStop, name, fieldName, and tableName. A compound property involves another object in font.color. As demonstrated in the previous example, you can alter the properties of objects with ObjectPAL.

Click Here to Read Part 1 | Click Here to Read Part 3

More Info

Article:  A 10 Minute ObjectPAL Quick Start
Article:  An ObjectPAL Primer: Part 1
Article:  An ObjectPAL Primer: Part 3

Comments

1 Comments.
Share a thought or comment...
Comment 1 of 1

While most college undergrads find their studies to be simple, checking through the assignments to make sure they are of high quality can still be a difficult task. To achieve the desired level of forcefulness, students hire professional writers to get the assistance of those who have a proven record of work with academic texts at pay for an essay online. The support from these creators is an unpredictable matter, as the Internet allows both legit authors and scammers to promote their services, and a student won’t differ simply one type of facilitator from another. So, what are your choices?

Posted 47 months ago
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1116A1
Enter key:
Article Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #100164 Counter
18465
Since 4/2/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]