Return values from ancestor scripts
If you want to perform some processing in an event in a descendent
object, but that processing depends on the return value of the ancestor
event script, you can use a local variable called AncestorReturnValue
that is automatically declared and assigned the return value of
the ancestor event.
The first time the compiler encounters a CALL statement that
calls the ancestor event of a script, the compiler implicitly generates
code that declares the AncestorReturnValue variable and assigns
to it the return value of the ancestor event.
The data type of the AncestorReturnValue variable is always
the same as the data type defined for the return value of the event.
The arguments passed to the call come from the arguments that are
passed to the event in the descendent object.
Extending event scripts
The AncestorReturnValue variable is always available in extended
event scripts. When you extend an event script, PowerBuilder generates
the following syntax and inserts it at the beginning of the event
script:
1 |
CALL SUPER::<i>event_name</i> |
You only see the statement if you export the syntax of the
object.
Overriding event scripts
The AncestorReturnValue variable is only available when you
override an event script after you call the ancestor event using
the CALL syntax explicitly:
1 |
CALL SUPER::<i>event_name</i> |
or
1 |
CALL <i>ancestor_name</i>::<i>event_name</i> |
The compiler does not differentiate between the keyword SUPER
and the name of the ancestor. The keyword is replaced with the name
of the ancestor before the script is compiled.
The AncestorReturnValue variable is only declared and a value
assigned when you use the CALL event syntax. It is not declared
if you use the new event syntax:
1 |
<i>ancestor_name</i>::EVENT <i>event_name</i>() |
Example
You can put code like the following in an extended event script:
1 |
IF AncestorReturnValue = 1 THEN |
1 |
// execute some code |
1 |
ELSE |
1 |
// execute some other code |
1 |
END IF |
You can use the same code in a script that overrides its ancestor
event script, but you must insert a CALL statement before you use
the AncestorReturnValue variable:
1 |
// execute code that does some preliminary processing |
1 |
CALL SUPER::ue_myevent |
1 |
IF AncestorReturnValue = 1 THEN |
1 |
... |