These are standard Xbase++ PRG files that are placed within a Xb2.NET web server's HTTP folder (www_root) and are dynamically compiled into a DLL when accessed by a web client. If the PRG script is modified, the DLL is automatically recompiled and the new code is loaded into server memory (with no user intervention). This feature was introduced in Xb2.NET v3.5.
No, the PRG files (or compiled DLLs) can be placed anywhere inside the web server's WWW root folder. In addition, it is possible to have
multiple script files with the same name but in different sub-directories and each serving different content, example:
http://mysite.com/sales/contact.prg
http://mysite.com/support/contact.prg
No problem. There are good reasons to avoid putting source code on a production HTTP server. Here are the options based on where the development and testing is done:
COPYDLL.BATbatch file to copy the new code onto the live server. The new DLL is automatically loaded and there is no need to restart the server.
That depends on whether PRG scripts will be dynamically compiled on the server or if pre-compiled DLLs will be simply copied into the server's HTTP folder.
XB2NET.LIBand
XB2NET.CH. These files can be placed in the HTTP server's application folder (where the .exe is installed).
PATH,
INCLUDE,
LIB,
XPPRESOURCE). A simple alternative is to copy the contents from the
.\bin,
.\liband
.\includeXbase++ installation folders into the Xb2.NET HTTP server application folder (where the .exe is installed).
There is no need to install the entire development environment. Just copy the contents from the .\XPPW32\
BIN
,
LIB
and INCLUDE
folders into the Xb2.NET HTTP server application folder (in fact, the list of files to be copied can be
further reduced because they are not all needed for compiling, eg: xppfd.exe, xppdbg.exe,...).
The rule is that the main procedure in the script file must have the same name as the PRG file itself. For example, assuming that the PRG file name = "TEST_123.PRG", then the script file must contain a procedure with the name "TEST_123":
File name: "TEST_123.PRG"
STATIC nCount := 0
// this is the main procedure (procedure name = file name)
PROCEDURE TEST_123()
++nCount
ThreadObject():HTTPResponse:Content := "<html><body>This is a test</body></html>"
Return
// returns number of times main procedure was called
PROCEDURE GetCount()
ThreadObject():HTTPResponse:Content := "<html><body>Count=" + str(nCount) + "</body></html>"
Return
If the script file (or compiled DLL) is placed in the .\www_root\
folder of mysite.com
, then the following URL will execute the desired function:
http://mysite.com/test_123.prg
If the script file is placed in the .\www_root\forum\sales\
folder of mysite.com
, then the following URL will execute the desired function:
http://mysite.com/forum/sales/test_123.prg
Yes, one script file may contain many functions or procedures, however before any of these can be executed the main procedure must be
called first (the procedure with the same name as the file itself - see Q7). The first call will compile the script
and/or load the DLL into memory. Once the DLL is loaded, any function/procedure without the STATIC
attribute can be executed from
a web client.
Using the TEST_123.PRG
example from Q7, to call the function GetCount
from a browser, use one of the following URLs:
http://mysite.com/GetCount()
http://mysite.com/forum/sales/GetCount()
Alternatively, the parenthesis in the above URLs may be replaced with a question mark ?
, eg:
http://mysite.com/GetCount?
http://mysite.com/forum/sales/GetCount?
Use one of the following options:
&). For example, to call the function
SpecialAdd, passing 2 params, do this:
nTotal := &('SpecialAdd')(n1, n2)
#pragmacommand, example:
#pragma library("myfuncs.lib")
The Xbase++ linker (ALINK) is unable to locate a function/procedure referenced within the PRG script. If the referenced symbol is part of
the Xb2.NET library, then simply add the following line at the top of the prg file:
#pragma library("xb2net.lib")
If the symbol is found within the main executable, then see Q9 above.
When a PRG script is modified, the following actions take place:
EXIT PROCEDUREto do this like in the WebShop Checkout sample.
INITand
EXIT PROCEDURES. See State Persistence sample.