| Previous | Contents | Index |
If embedded code inside a SheerPower script area starts with a $ (dollar sign) then what follows the $ is treated as a CGI symbol lookup. The result of that lookup is then sent to the browser. For example, to send the HTML to the browser the value of CITY (where CITY was received from a browser form submit action):
The city was: <<$CITY>> |
CGI Symbol Names are case sensitive. |
20.5 High Performance PERSIST Tags
<<%persist>> ... ... <</%persist>> |
<<%persist>>
<<%spscript>>
<html>
<head>
<title>Search Form</title>
</head>
<body onload="document.forms[0].city.select()">
<h2>Search for a city</h2>
<</%spscript>>
counter++
print '<h2>Counter: '; counter;'</h2>'
process$ = getsymbol$('process')
select case process$
case ''
display_form
case 'show_results'
display_form
do_show_results
case else
print 'Unknown process: '; process$
end select
print '</body>'
print '</html>'
<</%persist>>
|
The <<%persist>> and <</%persist>> tags will provide your program with a higher performance.
For high performance, a script can remain running longer than initially required using the <<%persist>> and <</%persist>> tags.
To use the tags, place the <<%persist>> tag at the beginning of the main logic area, and the <</%persist>> at the end of the main logic area.
The process included within the tags "goes away" after 10 seconds of inactivity.
In addition to the <<%persist>> tag, find any code that you want to run just once per persistance and surround it with the <<%once>> and <</%once>> tags. Good candidates are:
routine do_show_results <<%once>> open structure client: name 'c:\sheerpower\samples\client' <</%once>> |
20.6 Location of SheerPower Scripting Programs
SheerPower scripting programs must be located in the following directory:
SheerPower\sphandlers\scripts\sp4gl |
The scripting programs are not directly in the wwwroot folder purposely to increase security. They are parallel to it. The actual location of the program when it runs is:
wwwroot\..\scripts\sp4gl\ |
If you move wwwroot to a different location, then the location of the scripting program moves as well. For example, if you change wwwroot as follows:
spins_webserver -wwwroot d:\mystuff\ |
Then the new location that the scripting program should reside is:
d:\scripts\sp4gl |
And the parallel location the program will run from is:
d:\wwwroot\..\scripts\sp4gl |
See Section 18.1.4, Specify Any Root Folder on how to change the location of wwwroot in SPINS Webserver.
20.6.1 How to Invoke a SheerPower Script Program in the Browser
To invoke a SheerPower script program in your browser:
\sheerpower\sphandlers\spins_webserver.exe
|
http://localhost/test.spsrc
|
Routines written in other languages can be called and run from a SheerPower program.
Callable routines are stored in libraries. The LIBRARY statement tells SheerPower what library a routine is located in. The LIBRARY statement must be used to specify where routines are located they are called in a program.
The CALL statement calls routines and executes them. Any routine in a shared Windows library can be called and executed. The CALL and LIBRARY statements make programs more powerful, more versatile, and provide more programming options.
SheerPower 4GL can also run other programs from within SheerPower using the PASS instruction. See Section 10.8, Pass Commands to the Operating System. |
LIBRARY 'libr_name'
|
The LIBRARY statement is used to specify the libraries that will be used in a program.
The LIBRARY statement specifies libraries from which to CALL routines. The routines can be written in any Windows language that supports the standard calling interface (FORTRAN, BASIC, COBOL, etc.).
libr_name is the file specification of a library. The library can be one of the Windows supplied libraries, or a user-defined library. A library must be named with the LIBRARY statement before a routine is called from it. The library name must be a string constant in quotes.
CALL routine_name(arg [BY pass_mech], arg...)
|
| Example 21-1 LIBRARY and CALL statements |
|---|
library 'msvcrt.dll' a$ = space$(40) text$ = 'Hello there!' call 'strcpy' (a$, text$) print a$ end Hello there! |
The CALL statement is used to call and execute library routines. These routines can perform procedures so the programmer does not have to write the code from scratch.
The library to which the routine belongs must have been specified in a LIBRARY statement.
routine_name is the name of the routine being called. Some routines take arguments. arg is an argument that passes data to the routine or retrieves data from the routine. If more than one argument is passed, separate the arguments with commas:
CALL routine_name(arg, arg, arg...)
|
pass_mech refers to the mechanism by which values are passed to the routine. The default passing mechanism for integers is by value. The default passing mechanism for strings is by reference. Here is an explanation of the passing mechanisms available:
| BY REF | By reference. This is the default passing mechanism for strings and integer arrays. Arguments passed by reference can be changed by the routine they are passed to. |
| BY VALUE | By value. This is the default passing mechanism for integer data. Arguments passed by value cannot be changed by the routine they are passed to. |
All INTEGER VALUES AND REFERENCES are to LONG WORD (4 byte) INTEGERS. |
To pass integer arrays to external routines from SheerPower, you specify the name of the array along with "()". For example:
| Example 21-2 Passing integer arrays to external routines |
|---|
dim abc%(100) call thestuff (abc%() by ref) |
The system function _INTEGER can be used in conjunction with the library statements. This function returns resulting data associated with the CALL.
| Previous | Next | Contents | Index |