Object Events: Where do I put my code?


Hello Everyone

If you have been following along, you know I write a lot of object code on forms rather than putting code in the code library. I was recently asked; How do I know what object should get what code? This is a fair question and deserves a look. To start with lets look at what Alpha Software says about Object Events.

Object Events

Many events are triggered by Alpha Five objects, such as buttons, fields, and forms. The object events are generally triggered in response to the cursors movements into and out of the object (i.e., the changing of focus from one place to another).

So in other words, as the user navigates forms, enters data and clicks buttons the code you put on the objects helps the user get the desired results they expect.

Events for Button Objects

A button object can have scripts attached to the following events:

Event Name

Description

OnPush

The button is pressed. Use to run a script.

OnArrive

The button gets focus.

OnDepart

The button looses focus.

CanArrive

Just before the button gets focus.

CanDepart

Just before the button looses focus.

OnFlyover

When the mouse is over the object. Use to change the field’s colors or display a message.

OnFlyoverLeave

When the mouse pointer is no longer over the object.

Scripts are generally attached to a buttons OnPush event.

Typically the button will be used to start a new record, edit a record, save entry, delete records and or show other forms or reports. Most buttons are placed on the form and are designed for a specific purpose. Sometimes you may want to make the button conditional. What I mean by that is let’s say you have a button which sorts data in a browse in Descending order. To sort Ascending you could have another button or you could set the code to switch so that once sorted Ascending, the next click of the button sorts Descending. The following example is code on the OnPush event of a button on our Note Writer module in our contact management application.

if Note_Writer:button39.text = "Edit Follow Up Memo" then
    xmemo = "Followup"
    Note_Writer:button39.text = "Edit Contact Memo"
    Note_Writer:text1.text = "Follow-Up Memo"
else    
    xmemo = "Contact"
    Note_Writer:button39.text = "Edit Follow Up Memo"
    Note_Writer:text1.text = "Contact Memo"
end if
Note_Writer:text1.refresh()
Note_Writer:cond1.refresh()

Here we set a variable called xmemo to either Followup or contact from the Contact Activities form when the user clicks Open Memo Mgr

Memo Fields Show buttonThis calls the Note Writer Form and sets the first button text property to either Followup or Contact which then sets the conditional object to the correct page and displays the correct note.

NoteWriterNow lets look at  Type In Object Events

Events for Type-In Objects

The following events are triggered by all forms of the type-in object: Type-In, List boxes, Drop-Down lists, Radio buttons, Check boxes, Two-state, and Multi-state buttons:

Event Name

Occurs When

OnChange

The contents of the field object are changed. Use to detect when the field has been changed.

OnArrive

The field gets focus.

OnDepart

The field looses focus.

CanArrive

Just before the field gets focus.

CanDepart

Just before the field looses focus.

OnFlyover

When the mouse is over the object. Use to change the field’s colors or display a message.

OnFlyoverLeave

When the mouse pointer is no longer over the object.

For type-in fields, the OnChange event fires when the control looses focus. For radio button, two-state button, multi-state button, and list box fields, the OnChange event fires as soon as the fields value changes.

The object code written for type in events typically controls data entry. For example if the field pay_type = “Credit Card” then the ONDepart event would un-hide the credit card number field and make that field the next tab stop. If the pay_type <> “Credit Card” the tab order goes to some other field in the data entry order.

if paytype.text = “Credit Card” then

ccnbr.show()

ccnbr.Activate()

else

ccnbr.hide()

payID.Activate()

end if


There are many examples of Object Events in the Alpha Software’s help file. Simply search on Object Events to see them. With a little practice and and imagination, you can use object event coding to control object properties. If you watched our session on Having Fun with Graphics you saw what can be accomplished. Our Clock Calendar was completely written using object code and object properties.

Clock Calendar

Well that’s it for today’s session. On our next session we will look at more examples of Object Events and how they control forms on the screen. Hope you will stop back. Thanks again for stopping by and Remember, if you need help with an Alpha Software application or wish to inquire about a custom application for your business go to our website

www.cdc-takecharge.com

and inquire or contact

NLawson@cdc-TakeCharge.com

Have a great day.