DO wwScripting SET SAFETY OFF LOCAL loScript as wwScripting loScript = CREATEOBJECT("wwScripting") loScript.lSaveVFPSOURCECODE = .T. && Optional for demo so we can see the code loScript.lEditERRORS = .T. && Allow editing errors immediately loScript.lShowFullErrorInfo = .T. lcHTML = loScript.RenderAspScript(FULLPATH( "templates\SimpleAspScript.wcs") ) IF loScript.lError ? loScript.cErrorMsg IF !ISNULL(loScript.oException) ? loScript.oException.LineContents ? loScript.oException.Details ? loScript.oException.LineNo ENDIF ENDIF ShowHtml(lcHtml)
The parser essentially turns ASP style <%= %> expressions and <% %> Code blocks into a FoxPro PRG file that can be executed dynamically.
Here's an example of a script file:
<html> <body> Hello world. Time is: <%= DATETIME() %> <hr /> <% lcOutput = "" for x = 1 to 5 lcOutput = lcOutput + TRANS(x) + "<br>" endfor *** Write the result into the output stream Response.Write(lcOutput) %> Query Result:<hr /> <% SELECT Company from TT_CUST INTO CURSOR TQuery SCAN %> Company: <%= Company %><br /> <% ENDSCAN %> </body> </html>
which is turned into this Visual FoxPro code:
PARAMETERS _out _out = [] _out = _out + [<html>]+CHR(13)+CHR(10) _out = _out + [<body>]+CHR(13)+CHR(10) _out = _out + [Hello world. Time is: ] _out = _out + TRANSFORM( EVALUATE([ DATETIME() ]) ) _out = _out + []+CHR(13)+CHR(10) _out = _out + [<hr />] lcOutput = "" for x = 1 to 5 lcOutput = lcOutput + TRANS(x) + "<br>" endfor *** Write the result into the output stream Response.Write(lcOutput) _out = _out + []+CHR(13)+CHR(10) _out = _out + []+CHR(13)+CHR(10) _out = _out + [Query Result:<hr />] SELECT Company from TT_CUST INTO CURSOR TQuery SCAN _out = _out + []+CHR(13)+CHR(10) _out = _out + [Company: ] _out = _out + TRANSFORM( EVALUATE([ Company ]) ) _out = _out + [<br />] ENDSCAN _out = _out + []+CHR(13)+CHR(10) _out = _out + [</body>]+CHR(13)+CHR(10) _out = _out + [</html>]
The scripting class manages the translation of the script code into this foxpro code as well as compiling and executing of the code. A variety of options determine exactly how the execution performs.
If lShowFullErrorInfo is set to .T. the error info includes a display of the source code surrounding the error, so it is easier to find the error. If lEditError is set to .t. wwScripting will open an editor window and attempt to highlight the error for you and allow you to fix the problem.