Progress
Programming
Handbook
Shared Objects
In general, without procedure parameters, the context of a called external procedure is invisible to the calling procedure. For example,
p-exprc2.p
(in the previous examples) cannot directly access the customer buffer defined inp-exprc1.p
. Also for external procedures, the context of the calling procedure is generally invisible to the called procedure. In other words, a procedure’s context is generally local to itself. However, external procedures can pass information and resources among them using shared objects (data, streams, or user interface widgets).Scoped Versus Global
There are two kinds of shared objects: scoped and global. A scoped shared object is accessible from the point of creation only for the scope of the procedure that first defines it. A global shared object is accessible from the point of creation until the end of the Progress session. Thus a called procedure can reference a scoped shared object that is created by a calling procedure (or any other procedure still on the call stack) prior to the call. Any procedure can access a global shared object after it is created.
NOTE: Any scoped shared objects created or referenced in the context of a persistent procedure remain available as long as the procedure persists. For more information, see the "Persistent and Non-persistent Procedures" section.Figure 3–2 shows how you can reference scoped and global shared objects outside of the procedure context in which they are created. (By definition, a procedure can reference any shared object created in its own context.) The Main Procedure starts out by creating scoped shared object A. It subsequently calls Subprocedure 1, which creates global shared object B and scoped shared object C. Subprocedure 1 calls Subprocedure 2 and the Main Procedure subsequently calls Subprocedure 3.
Figure 3–2: Object Sharing Among External Procedures
![]()
All the procedures can reference A because it is created in the Main Procedure, before any subprocedures are called. All procedures except the Main Procedure can reference B even though it is created in a subprocedure, because B is global. Note that the Main Procedure cannot reference global B, because when the Main Procedure is compiled, B has not yet been created. Subprocedure 2 is the only procedure that can reference all of shared objects A, B, and C because it is called within the scope of scoped objects A and C. Subprocedure 3 can only reference A and B, because C is out of scope.
Thus, a scoped shared object is accessible to any procedure, as long as the initial procedure that creates the object is still in scope. A global shared object is accessible to any procedure as long as the initial procedure that creates the object has executed prior to the first reference to the object, whether or not the initial procedure is still in scope.
Defining and Referencing
Any object defined using the NEW SHARED option in its DEFINE statement creates a scoped shared object. Any object defined using the NEW GLOBAL SHARED option creates a global shared object. Any object defined using the SHARED option (without NEW or GLOBAL) creates a reference to a previously created scoped or global shared object. Currently, the only objects that can be globally shared are variables and streams. For example, the following procedures define and use both scoped and global shared variables:
Procedure
p-share1.p
defines a scoped shared variable (sharedvar) thatp-share2.p
andp-share3.p
can reference, andp-share2.p
defines a global variable (globvar) thatp-share3.p
can reference. Note thatp-share1.p
cannot reference globvar becausep-share1.p
compiles and references any variable beforep-share2.p
can define it.For information on shared buffers, see "Database Access," in this manual, and on shared streams, see Alternate I/O Sources." Any other Progress objects that include the NEW and SHARED keywords in their definition can also be shared. For more information, see the DEFINE statement for the objects in the Progress Language Reference .
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |