Global shared objects in ABL
- Last Updated: August 3, 2023
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
GLOBAL keyword in the
definition:
|
NEW SHARED can also be defined as NEW
GLOBAL SHARED. For example, one procedure can have this global
definition:
|
|
One tricky aspect to this is the after that procedure requirement. In many applications, it is not easy to determine which of the procedures that might want to reference a value will execute first, and therefore should be the procedure that defines it. Or you might have many procedures that need to reference the value and not know which of them will execute at all in the course of a session.
ABL provides a work-around for this problem. If a procedure defines an object as
NEW GLOBAL SHARED and another procedure has already registered this
definition, then no error results. The AVM ignores the NEW GLOBAL part
of the second definition and accepts it as a reference to the existing
SHARED object. This is different from non global shared objects,
where a second NEW SHARED reference causes a run-time error.
For this reason, it is common practice simply to use the NEW GLOBAL
SHARED syntax in every procedure that needs to use the objects. Although
this is somewhat contradictory to the way the non global shared syntax works, it is
reliable behavior.