Progress
Language Tutorial
for Windows
Using Shared Variables
When you define a variable in one procedure, you can only use it in that procedure or the internal subprocedures of that procedure. This kind of variable is known as a local variable. If you want more than one procedure to use a variable, then you need to use a shared variable. To defined a shared variable, use the DEFINE VARIABLE statement.
When you use a shared variable, only one procedure can own the shared variable. That procedure creates it, and when that procedure ends, so does the availability of the shared variable. The owner procedure must use the two keywords NEW SHARED in the DEFINE VARIABLE statement, as in this example:
Any other procedure that uses the shared variable must also define it, but without the keyword NEW:
Note that any format phrase option, such as a label or format string, specified in the original definition (NEW SHARED), does not apply to the variable in subsequent definitions (SHARED). You can specify different options for the variable in different procedures.
Also note that you cannot define shared variables in a user-defined function.
Figure 6–5 shows the relationship among three procedures and the shared variable that two of these procedures access. The
proc1.p
procedure defines a NEW SHARED variable called Shareinfo and runs a procedure calledproc2.p
. Theproc2.p
procedure does not use Shareinfo but callsproc3.p
, which does. Procedureproc3.p
needs to define Shareinfo as a shared variable. Even though you don’t runproc3.p
fromproc1.p
, it still can still access the shared variable. Onceproc1.p
defines the variable, any procedure that also defines that variable can access the data stored there.Figure 6–5: Shared Variables
![]()
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |