Return
values from ancestor scripts
If you want to perform some processing in an event in a descendant
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 datatype of the AncestorReturnValue variable is always the same
as the datatype 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 descendant 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::event_name |
You see the statement only if you export the syntax of the
object.
Overriding event scripts
The AncestorReturnValue variable is available only when you override
an event script after you call the ancestor event using the CALL syntax
explicitly:
|
1 |
CALL SUPER::event_name |
or
|
1 |
CALL ancestor_name::event_name |
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 declared and a value assigned
only when you use the CALL event syntax. It is not declared if you use the
new event syntax:
|
1 |
ancestor_name::EVENT event_name ( ) |
Example
You can put code like the following in an extended event
script:
|
1 2 3 4 5 |
IF AncestorReturnValue = 1 THEN // execute some code ELSE // execute some other code 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 2 3 4 |
// execute code that does some preliminary processing CALL SUPER::ue_myevent IF AncestorReturnValue = 1 THEN … |