About functions and events
Importance of functions and events
Much of the power of the PowerScript language resides in the
built-in PowerScript functions that you can use in expressions and
assignment statements.
Types of functions and events
PowerBuilder objects have built-in events and functions. You
can enhance objects with your own user-defined functions and events,
and you can declare local external functions for an object. The
PowerScript language also has system functions that are not associated
with any object. You can define your own global functions and declare
external functions and remote procedure calls.
The following table shows the different types of functions
and events.
|
Category |
Item |
Definition |
|---|---|---|
|
Events |
Event |
An action in an object or control that |
|
User event |
An event you define to add functionality |
|
|
System or built–in event |
An event that is part of an object’s |
|
|
Functions |
Function |
A program or routine that performs specific processing. |
|
System function |
A built-in PowerScript function that |
|
|
Object function |
A function that is part of an object’s |
|
|
User-defined function |
A function you define. You define global |
|
|
Global function |
A function you define that can be called |
|
|
Local external function |
An external function that belongs to |
|
|
Global external function |
An external function that you declare |
|
|
Remote procedure call (RPC) |
A stored procedure in a database that |
Comparing functions and events
Functions and events have the following similarities:
-
Both
functions and events have arguments and return values. -
You can call object functions and events dynamically
or statically. Global or system functions cannot be called dynamically. -
You can post or trigger a function or event call.
Functions and events have the following differences:
-
Functions can be global or part of an object’s
definition. Events are associated only with objects. -
PowerBuilder uses different search orders when looking
for events and functions. -
A call to an undefined function triggers an error.
A call to an undefined event does not trigger an error. -
Object-level functions can be overloaded. Events
(and global functions) cannot be overloaded. -
When you define a function, you can restrict access
to it. You cannot add scope restrictions when you define events. -
When functions are inherited, you can extend the
ancestor function by calling it in the descendant’s script.
You can also override the function definition. When events are inherited,
the scripts for those events are extended by default. You can choose
to extend or override the script.
Which to use
Whether you write most of your code in user-defined functions
or in event scripts is one of the design decisions you must make.
Because there is no performance difference, the decision is based
on how you prefer to interact with PowerBuilder: whether you prefer
the interface for defining user events or that for defining functions,
how you want to handle errors, and whether your design includes
overloading.
It is unlikely that you will use either events or functions
exclusively, but for ease of maintenance, you might want to choose
one approach for handling most situations.