wwScripting :: RenderASPScript

Renders an ASP style page as a compiled VFP program. This method handles creation of the VFP source code from the script file, compilation and checking for updates of the file.

Parsing works using ASP style syntax:

<%= Expression  %>

<%
VFP Code Block
%>

The script page gets passed a Response object which you can USE to send output directly into the output stream.

Using the wwScripting Class to Parse FoxPro ASP Script

The following is an example of how to create the wwScripting instance and use it to render ASP style scripting. This compiles the code into a PRG file and executes the resulting PRG file.

First here's a reusable method to create an instance of wwScripting setup for script execution:

************************************************************************
FUNCTION CreatewwScripting(llDebugMode)
****************************************

loScript = CREATEOBJECT("wwScripting")

*loScript.cScriptResponseClass = "wwPageResponse"
loScript.lNoVersionCheck = .F.
loScript.lEditErrors = .F.
loScript.lSaveVfpSourceCode = .F.
loScript.lShowFullErrorInfo = .F.
loScript.cBasePath = "c:\webconnection\fox\tests"

*** Write output directly into this Response object
*loScript.oResponse = CREATEOBJECT("wwPageResponse")

IF llDebugMode
	loScript.lShowFullErrorInfo = .T.
	loScript.lEditErrors = .T.
	loScript.lStopOnError = .T.
ELSE
    *** We want the exception to bubble up to Web Connection error handler
    loScript.lThrowException = .T.	
ENDIF

RETURN loScript
ENDFUNC
*   CreatewwScripting

And here is a simple Test method that uses this to execute the script code:

************************************************************************
FUNCTION TestwwScripting
****************************************

lcText = "This " +CHR(10)+ "is one line of text" + CHR(10) + " separated by CHR(10)s <%= VERSION() %>" + CHR(10) + CHR(10) 

TEXT TO lcText2 NOSHOW
<%  x = 1 
    x = x + 2
%>

Value is: <%= x %>    
ENDTEXT

lcText = lcText + lcText2

lcFile = "c:\webconnection\fox\tests\test.wcs"
STRTOFILE(lcText,lcFile)

loScript = THIS.CreatewwScripting()
loScript.lSaveVfpSourceCode = .t.

*** Create output from the rendered script as a string
lcOutput = loScript.RenderAspScript(lcFile)

THIS.MessageOut(lcOutput)
ENDFUNC
*   TestwwScripting
o.RenderAspScript(lcTemplate)

Return Value

Evaluated result from the script code.

Parameters

lcTemplate Name of the file on disk to parse

Remarks

Be careful with this class in multi-user environments. The version checks for the script will cause recompilation if a change is made to source code, however, if multiple clients are accessing these scripts only the first access will detect the change and recompile and update the script in memory. Other clients will see the script up to date and not refresh.

This class is primarily meant for client side implementations, especially for applications working with the Web Browser control for rendering display content in Desktop applications.

It also works for server side implementations where dynamic change or updates of scripts is not required. It is not recommended as a server side scripting engine. It can be used with Active Server Pages and ASP.NET however, since these environments load and unload VFP on every hit and thus release the procedure stack.

Example

lcFileName = "~\SomePage.wcs"
* lcFileName = "c:\WebApps\MyWebApp\Web\SomePage.wcs"

lcBasePath = Request.GetApplicationPath()  && root path for application

loScript = CREATEOBJECT("wwScripting")
loScript.lNoVersionCheck = .F.
loScript.lEditErrors = .F.
loScript.lSaveVfpSourceCode = .T.
loScript.lShowFullErrorInfo = .F.	
loScript.cBasePath = ADDBS(lcBasePath)	

lcResult = loScript.RenderAspScript(lcFilename)  

if loScript.lError
   *** also oException is set with error props and line info
   ? loScript.cErrorMsg 
   return
ENDIF

? lcResult

See also:

Class wwScripting

© West Wind Technologies, 2023 • Updated: 01/24/17
Comment or report problem with topic