sharing_20private_20variables
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
sharing_20private_20variables [2018/03/31 13:19] – external edit 127.0.0.1 | sharing_20private_20variables [2024/01/05 00:21] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 4: | Line 4: | ||
===== Method one ===== | ===== Method one ===== | ||
\\ This method relies on providing a common //entry point// for the procedures and functions, so that the **PRIVATE** statement may be placed there, as follows:\\ \\ | \\ This method relies on providing a common //entry point// for the procedures and functions, so that the **PRIVATE** statement may be placed there, as follows:\\ \\ | ||
+ | <code bb4w> | ||
DEF PROCone(parameters) : LOCAL type% : type% = 1 | DEF PROCone(parameters) : LOCAL type% : type% = 1 | ||
DEF PROCtwo(parameters) : LOCAL type% : type% = 2 | DEF PROCtwo(parameters) : LOCAL type% : type% = 2 | ||
Line 14: | Line 15: | ||
ENDCASE | ENDCASE | ||
ENDPROC | ENDPROC | ||
+ | </ | ||
This method can be expanded to as many procedures and functions as are required to share the PRIVATE data. It is even possible to share the data between a procedure and a function, so long as the **ENDPROC** or **=** statement is placed within the appropriate **WHEN** clause:\\ \\ | This method can be expanded to as many procedures and functions as are required to share the PRIVATE data. It is even possible to share the data between a procedure and a function, so long as the **ENDPROC** or **=** statement is placed within the appropriate **WHEN** clause:\\ \\ | ||
+ | <code bb4w> | ||
DEF PROCone(parameters) : LOCAL type% : type% = 1 | DEF PROCone(parameters) : LOCAL type% : type% = 1 | ||
DEF FNtwo(parameters) : LOCAL type% : type% = 2 | DEF FNtwo(parameters) : LOCAL type% : type% = 2 | ||
Line 27: | Line 30: | ||
ENDCASE | ENDCASE | ||
REM. Execution should never reach here. | REM. Execution should never reach here. | ||
+ | </ | ||
\\ | \\ | ||
===== Method two ===== | ===== Method two ===== | ||
\\ This method relies on creating a **structure** to hold the private data, as follows:\\ \\ | \\ This method relies on creating a **structure** to hold the private data, as follows:\\ \\ | ||
- | | + | <code bb4w> |
- | PRIVATE ps{} | + | |
- | PROCprivate(ps{}) | + | PRIVATE ps{} |
- | REM. Code for PROCone goes here. | + | PROCprivate(ps{}) |
- | REM. Private variables are ps.alpha, ps.beta%, ps.gamma$ | + | REM. Code for PROCone goes here. |
- | ENDPROC | + | REM. Private variables are ps.alpha, ps.beta%, ps.gamma$ |
+ | ENDPROC | ||
- | | + | |
- | PRIVATE ps{} | + | PRIVATE ps{} |
- | PROCprivate(ps{}) | + | PROCprivate(ps{}) |
- | REM. Code for FNtwo goes here. | + | REM. Code for FNtwo goes here. |
- | REM. Private variables are ps.alpha, ps.beta%, ps.gamma$ | + | REM. Private variables are ps.alpha, ps.beta%, ps.gamma$ |
- | = returnvalue | + | = returnvalue |
- | | + | |
- | PRIVATE p{} | + | PRIVATE p{} |
- | DIM p{alpha, beta%, gamma$} | + | DIM p{alpha, beta%, gamma$} |
- | !(^t{}+0) = !(^p{}+0) | + | |
- | !(^t{}+4) = !(^p{}+4) | + | |
- | ENDPROC | + | ENDPROC |
+ | </ | ||
The **PROCprivate** procedure sets the supplied structure parameter to point to the private structure declared therein, allowing any routine which calls this procedure to access the private data.\\ \\ You can use the same technique to share PRIVATE arrays:\\ \\ | The **PROCprivate** procedure sets the supplied structure parameter to point to the private structure declared therein, allowing any routine which calls this procedure to access the private data.\\ \\ You can use the same technique to share PRIVATE arrays:\\ \\ | ||
+ | <code bb4w> | ||
DEF PROCone(parameters) | DEF PROCone(parameters) | ||
PRIVATE array() | PRIVATE array() | ||
Line 66: | Line 73: | ||
PRIVATE array() | PRIVATE array() | ||
DIM array(100) | DIM array(100) | ||
- | | + | |
ENDPROC | ENDPROC | ||
+ | | ||
+ | DEF FNgetarrayptr(RETURN a%%) = a%% | ||
+ | DEF PROCsetarrayptr(RETURN a%%, p%%) : a%% = p%% : ENDPROC | ||
+ | </ |
sharing_20private_20variables.1522502381.txt.gz · Last modified: 2024/01/05 00:16 (external edit)