Understanding Properties, Events, and Methods


 

Visual PL./B forms and controls are objects that expose their own properties, methods and events. Properties can be thought of as an object's attributes, methods as its actions, and events as its responses.

 

An everyday object like a child's helium balloon also has properties, methods and events. A balloon's properties include visible attributes such as its height, diameter, and color. Other properties describe its state (inflated or not inflated) or attributes that aren't visible such as its age. By definition, all balloons have these properties but the settings of these properties may differ from one balloon to another.

 

A balloon also has inherent methods or actions that it might perform. It has an inflate method (the action of filling it with helium), a deflate method (expelling its contents) and a rise method (if you were to let go of it). Again, all balloons are capable of these methods.

 

Balloons also have predefined responses to certain external events. For instance, a balloon would respond to the event of being punctured by deflating itself or to the event of being released by rising into the air.

 

If you were able to program a balloon, the Visual PL/B code might look like the following. To set the balloon's properties:

 

     SETPROP      BALLOON,COLOR=RED

     SETPROP      BALLOON,DIAMETER=10

     SETPROP      BALLOON,INFLATED=$True

 

or more efficiently:

 

     SETPROP      BALLOON,COLOR=RED,DIAMETER=10,INFLATED=$True

 

Note the syntax of the code - the object (BALLOON) followed by the property (.COLOR) followed by the assignment of the value (RED). You could change the color of the balloon from code by repeating this statement and substituting a different value. Properties can also be set in the Properties window of the Designer.

 

A balloon's methods are invoked like this:

 

     BALLOON.INFLATE

     BALLOON.DEFLATE

     BALLOON.RISE USING "5"

 

The syntax is similar to the property - the object (a noun) followed by the method (a verb). In the third example, there is an additional item, called an argument, which denotes the distance to rise. Some methods will have one or more arguments to further describe the action to be performed.

 

The balloon might respond to an event as follows:

 

Balloon_Puncture

     Balloon.Deflate

     Balloon.MakeNoise using "Bang"

     SETPROP            Balloon.Inflated=$False,Diameter=1

     RETURN

 

In this case, the code describes the balloon's behavior when a puncture event occurs: invoke the Deflate method, then invoke the MakeNoise method with an argument of "Bang" (the type of noise to make). Since the balloon is no longer inflated, the Inflated property is set to False and the Diameter property is set to a new value.

 

While you can't actually program a balloon, you can program a Visual PL/B form or control. As the programmer, you are in control. You decide which properties should be changed, methods invoked or events responded to in order to achieve the desired appearance and behavior.



PL/B IDE Studio Help Forms, Controls, and Menus Clicking Buttons to Perform Actions