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 can start the |
|
|
User event |
An event you define to add functionality to an |
|
|
System or built-in event |
An event that is part of an object’s PowerBuilder |
|
Functions |
Function |
A program or routine that performs specific |
|
|
System function |
A built-in PowerScript function that is not |
|
|
Object function |
A function that is part of an object’s definition. |
|
|
User-defined function |
A function you define. You define global functions in |
|
|
Global function |
A function you define that can be called from any |
|
|
Local external function |
An external function that belongs to an object. You |
|
|
Global external function |
An external function that you declare in any painter, |
|
|
Remote procedure call (RPC) |
A stored procedure in a database that you can call |
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.