ActiveVFP Documentation

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 18
At a glance
Powered by AI
ActiveVFP is a framework for building web applications using Visual FoxPro. It allows developers to create dynamic web pages by integrating VFP code with ASP.NET pages. Some of the main components include the ASPX/ASP page, ActiveVFP class library, HTML templates, and a main VFP program file.

Some of the main components of ActiveVFP include the ASPX/ASP page which acts as an interface, the ActiveVFP class library contained in the activevfp.dll, HTML templates to control the application interface, and a main VFP program file containing application logic. Templates can include VFP code using expressions.

Some key ActiveVFP classes include AVFPhtml for generating HTML, AVFPhttpupload for file uploads, AVFPpdf for generating PDFs, AVFPproperties for accessing properties, AVFPrequest for form and query string data, AVFPresponse for redirects, AVFPsession for session management, and AVFPsql for database access.

ActiveVFP Documentation

Version 4.1

Introduction
    Requirements
    Support
    Free Add-on Downloads
    Basics
Step by Step Simple Example
HTML Templates
    <%= %> Expressions and Variables
    <tablename> </tablename>
WebAppBuilder
Debugging
Installation and Distribution
    PostSetup
    Sample InstallShield Project
    InstallShield Custom Actions
Networked DBFs
MS SQL
COM+ Setup
Reporting/Printing
Other Tools
    SMTP E-Mail with CDO
    Charts and Graphs with OWC (Office Web Components)
    FTP and other Internet functions
    Full-text search
    Timers
ActiveVFP Classes, Methods, and Properties
    AVFPasync Class
        CreateThread Method
        Check Method
        Count Property
        RecordError Method
        Err Property
        Err_txt Property
        Returnval Property
        StartWebEvent Method
        CompleteWebEvent Method
        StatusWebEvent Method
    AVFPcookie Class
        Write Method
        Delete Method
    AVFPhtml Class
        HTMLtable Method
        MergeText Method
        MergeScript Method
        HTMLdropdown Method
    AVFPhttpupload Class
        SetMaxSize Method
        HTTPupload Method
    AVFPpdf Class
        Start Method
    AVFPproperties Class
        Action Property
        HtmlPath Property
        AppStartPath Property
        ScriptPath Property
        SessID Property
        AppName Property
    AVFPrequest Class
        QueryString Method
        Form Method
        Cookies Method
        ServerVariables Method
        DumpVars Method
    AVFPresponse Class
        Redirect Method
    AVFPsession Class
        Value Method
    AVFPsessiontable Class
        Value Method
    AVFPsql Class
        Login Method
        Execute Method
        cSqlCursor Property
       
Requirements:
Microsoft IIS 5(Win2k) or greater.  IIS 7 (Vista) requires that the IIS 6 Metabase and
compatibility component be installed. 
.Net Framework 2 or higher (make sure .NET 2.0 is set as the default in IIS if there
are multiple versions)
Microsoft Visual FoxPro 7 SP1, or above.
Any HTML editor (a WYSIWYG editor like MS Expression is highly recommended).
Note: Only Administrator or equivalent user can run the setup.

Optional :
Active Server Pages
GhostScript 8.54 for web reporting (see free downloads below)
Office Web Components for web graphs (see free downloads below)

Support:
http://activevfp.codeplex.com

Downloads:
ActiveVFP makes use of the following free downloads:

.Net Framework 2.0 or greater for ASP.NET pages to be used with ActiveVFP -
http://www.microsoft.com/downloads/details.aspx?FamilyID=0856EACB-4362-4B0D-
8EDD-AAB15C5E04F5&displaylang=en
*Note: the .NET Framework is already included in Windows VISTA OS and later.
 
VFP Report To PDF
AFPL Ghostscript 8.54 and a PostScript printer driver(defpscol.zip is included in the
setup)

Office Web Components(OWC) for Web Charting -


http://office.microsoft.com/downloads/2002/owc10.aspx
 

Basics:

er<--> IIS default.aspx <--->main.prg <-->images


web <--> default.asp <---> ActiveVFP.dll (mtdll) <--->HTML templates <--->E-mail templates
JSON,etc) server  <--->background threads <--->DB
(ISAPI dll)

default.aspx - this is a basic page with minimal code.  Using ActiveVFP, you could
almost consider the ASPX  page as an .ini file - you can set various properties like
caching, etc.  Other than that, the main part of the ASPX/ASP page is calling the
activevfp mtdll and it's main method.

activevfp.dll (vfp mtdll) - this is where the ActiveVFP framework resides.

main.prg - this is where your application logic can go.  Alternatively, you could place most of
your application code within the HTML templates themselves. 

HTML and e-mail templates - this is where you control the look and feel of the
application.  VFP variables and expressions are contained between <%= and %>
and are evaluated when the application is run.  AVFP  also has the ability to include
VFP code blocks within the HTML template.  See the mergescript method.

Step by step simple example:


1.)  Start WebAppBuilder.app and specify the name of the application and the
physical directory where it should go.  Press the build button.  (name and directory
are the names you put into the web builder and will be referred to below).  After the
application is built, it should automatically pop up a browser with a 'hello world'
example.

2.)  Go to  directory\name\prg and open main.prg.   In the the main case statement,
find the following string: CASE oProp.Action=='hello' and change the 'Hello world'
output to something else.  Save and compile main.prg.      

3.) From your browser, type in the following:


http://localhost/name/default.aspx?action=hello .  This should bring up the web
application you created with the new string.

4.) Now open your html editor and create a basic HTML document.

5.) Place the following in your html document within the <body></body> tags:

Hello world from ActiveVFP using an HTML template!


Visual FoxPro date and time is <%=DATETIME()%>.  

Save the file to the directory\name\html  directory.  We'll now refer to the HTML file
as HTMLfile.   

6.) Go back into the name.pjx and open the main.prg again.  In the main CASE
statement, find CASE oProp.Action=='hello' and replace those lines of code with the
following lines:

lchtmlfile = 'HTMLfile'    && your HTML file with the extension like 'test.htm'
lcHTMLout= FILETOSTR(oProp.HtmlPath+lcHTMLfile)
lcHTMLout= oHTML.mergetext(lcHTMLout)

7.)  Save and compile main.prg.     

8.)  From your browser, type in the following:

http://localhost/name/default.aspx?action=hello .  This should bring up the web


application using the new HTML template you just created.

9.)  To interactively debug this web application, do the following:


Recompile name.dll to name.exe (debugging requires an EXE COM server)
From the command window: cd c:\directory\name
From the command window: do c:\directory\name\prg\webappdebug.prg

10.)  After you've finished developing your web app and you want to distribute it, go
to the  c:\directory\name\InstallShield directory, open up MyWebApp.ism, and
replace the 'avfpdemo4' string with name everywhere that 'avfpdemo4' occurs.

11.)  For more examples, including interaction with data and HTML tables, please
examine the included avfpdemo4 application.  The source is located in AVFPinstall
Dir\avfpdemo4\.

NOTE:  Even though a new project is created with the specified web app name, this
is for reference and convenience only.  No need to compile this to a new mtdll since
the ActiveVFP web framework is being used from the activevfp.dll already installed. 
All new development will be done in Main.prg and/or the HTML templates (all files
marked external in the project including background thread code for asynchronous
processing). 

HTML Templates:
<%= %> Expressions and Variables
Within the HTML templates, place any VFP variable or expression between the
standard <%= %> delimiters.  The variables and expressions will be evaluated and
replaced by their values when either the mergetext method or the htmltable method
are run.
For example,  Total Customers=<%=reccount()%>  or  <%=tCursor.Contact%>

<tablename> </tablename>
Each HTML table enclosed within table label brackets will be evaluated and replaced
with the records of the currently open table.  The top row of the table should include
<TH> cells if you want to include headers.  Do not place headers in <TD> cells. 
Having no headers at all will work fine.

For example, the following will produce a table list of all customers selected into tCursor:
<customers>

Company Contact Title


<%= tCursor.Title
<%=tCursor.company%> <%=tCursor.Contact%>
%>

</customers>

You may place as many tables to be evaluated as desired on an HTML page.

WebAppBuilder:
WebAppBuilder.app is located in the root installation drive.  When you run it, you will
provide 2 pieces of information: the application name and the drive and directory
where you would like to place the new application files. Optionally, you can change
the default Domain and default WebSite if you're running multiple sites.  Given this
information, WebAppBuilder will create the web application directory structure,
create the virtual directories, and finally launch the browser to the new app.
The application directory that is created has the following structure (assume
c:\dotcomsolution is the name of the directory and HelloWorld is the name of the
app:

c:\dotcomsolution
       c:\dotcomsolution\helloworld
            activevfp.dll (vfp mtdll can go here if it isn't somewhere else)
                c:\dotcomsolution\helloworld\wwwroot (scripts directory)
                    default.aspx
                    default.asp
                    c:\dotcomsolution\helloworld\wwwroot\bin (avfp dotnet proxy dll) 
                c:\dotcomsolution\helloworld\html
                    (html templates go here) 
                c:\dotcomsolution\helloworld\prg
                    (all .prg files)
      c:\dotcomsolution\helloworldr (read-only directory)
                c:\dotcomsolution\helloworldr\images
                c:\dotcomsolution\helloworldr\pdffiles
                c:\dotcomsolution\helloworldr\temp
      c:\dotcomsolution\data
               c:\dotcomsolution\data\helloworld  
      c:\dotcomsolution\errorlog
               c:\dotcomsolution\errorlog\helloworld  

In addition, /helloworld (scripts) and /helloworldr (read) virtual directories are created.

Debugger:
To interactively debug an ActiveVFP web application and use the regular VFP
debugger, do the following:
1.) Recompile your mtdll to an exe.  For example, avfpdemo4.dll to avfpdemo4.exe
(debugging requires an EXE COM server)
2.) From the command window: cd c:\dotcomsolution\avfpdemo4 (adjust for your
app's location)
3.) From the command window: do
c:\dotcomsolution\avfpdemo4\prg\webappdebug.prg . 

(Optionally, Visual Studio .NET could be used to debug if you have it)

Installation and Distribution:


PostSetup
Use PostSetup as your InstallShield postsetup executable.  Source code includes:
PostSetup.cpp - code that launches the VFP MTDLL PostSetup server.
PostSetup.prg - code that determines OS, web server, ADSI, and folder
permissions.  Launches default web browser and default web app at the end of
setup.

InstallShield Sample Project


MyWebApp.ism - sample project for the free InstallShield version included with VFP
7 and above.  Replace the avfpdemo4 string (where ever it occurs in the project) with
the name of your product.

InstallShield Custom Actions


Use these to run automatically from the full version of IS Express:
islaunch.cpp - launches PostSetup as an InstallShield Custom Action.
isremove.cpp - InstallShield Custom Action that reminds user to remove virtual
directories.  Actual removal of virtual directories could go here.

Networked DBFs and MSDE/SQL setup:


To access dbf data across the network (not on the local machine) or to use SQL
Server or MSDE data, you must set up your vfp mtdll in COM+.  The directions for
doing this are listed next.
COM + Setup Instructions for a VFP mtdll (on
Windows2000):
1.) go into Control Panel, Component Services
2.) right click COM+ applications and select New.
3.) going through the wizard, create an Empty Application, giving it a name, check
server application, and select the appropriate   account to run under.
4.) After the Empty Application is created, right click on 'Components' under the
newly created application.
5.) select New/Component.
6.) The wizard starts - select 'Import components that are already registered.'
7.) select your Visual FoxPro mtdll from the list and it is added to this COM+ app.
8.) right click on your COM+ application name and select 'Start'. The COM+ icon is
now revolving in the Components pane.

Reporting
Reporting in AVFP or any vfp mtdll is accomplished by putting the SET PRINTER
and REPORT FORM statements in a VFP COM EXE, creating that object from your
main.prg, and calling the method that does the REPORT FORM from main.prg.  See
the PDF routine in the avfpdemo4 application for an example of this.

GhostScript can be used to create PDF reports from regular VFP reports and
AVFPdemo4 has some examples. 

Instructions
1.) Download and install AFPL Ghostscript 8.54 .
2.) Install a PostScript printer driver:  Download the Driver
Download Adobe's self-installing executable PostScript driver, universal installer
version 1.0.6 or later, for Windows 95/98/Me/NT/2000/XP. (You can browse for other
versions of the driver on Adobe's web site.) Save the downloaded file, winsteng.exe,
to a temporary location, such as C:\TEMP.
You will also need a PostScript Printer Description (PPD) file. Use the Generic
Colour PostScript PPD in the zip file defpscol.zip (included in the setup and on the
web). Download and unzip this and extract the enclosed file, defpscol.ppd, to the
same temporary location as you downloaded the driver.
Installing the Driver:
* Find the file winsteng.exe which you downloaded earlier and double-click on it to
run it
* Accept the licence agreement
* Choose the connection type Local Printer (rather than Network Printer)
* When asked to choose a port to connect the printer to, choose FILE: (rather than
COM1:, COM2:, etc.)
* When asked to choose a printer model, you can choose the option Generic
PostScript Printer, but if you  would like to print in colour as well as black and white,
click on the Browse button and browse to the location where you unpacked
defpscol.ppd earlier and choose Generic Colour PostScript
* If asked, don't make this your default printer
* And don't try to print a test page yet
* If asked, say you do wish to configure your printer and check that the default paper
size is set to A4
3.) You must run DCOMCNFG on PDFrun.Print2PDF prior to use: Under Security for
PDFRun.Print2PDF, add Custom Access and Custom Launch permissions for the
IUSR, IWAM, and ASPNET accounts.
4.) Under the Identity tab for PDFRun.Print2PDF, make sure the Interactive user is
selected.
5.) For more information on using AVFPpdf, see the avfpdemo4 project source and
demo for a complete example.

ActiveVFP Classes, Methods, Properties:


AVFPasync Class (WebThreads.prg)
*Note: For Vista (and possibly later Window OSs), in order to use the AVFPasync
class, the Data Execution Prevention (DEP) feature must be turned off for
activevfp.dll.
XP SP2 (test the example first to see if you need this(I didn't)): 
1. Click Start
2. Select Control Panel
3. Select System
4. Click the Advanced tab
5. In the Performance region select Settings
6. Click the Data Execute tab in the dialog box that opens
7. Select Turn on DEP for all programs and services except for those I select
8. Click Add.
9. The open dialog box will open. Browse and select your application.
10. Click Open
11. Click Apply
12. Click Ok
13. Reboot
Vista:  1. Launch an elevated command prompt shell with administrative privileges
and credentials (log on to Windows Vista with a user account with administrator
rights, and then right click on Command Prompt icon and select “Run as
Administrator, or turn off UAC).
2.  Execute the following command: bcdedit.exe /set {current} nx AlwaysOff
3.  Reboot

CreateThread - Start a thread running in the background and monitor it.


Syntax:
oAsync=CREATEOBJECT("ThreadManager")  &&create the thread manager
cID=oAsync.CreateThread(cProgram)  &&start the background thread
Parameters:
 cProgram - Whichever program is being launched in a background thread.
Returns:
 cID - Unique thread ID to keep track of.

Check - Check to see if the background thread has finished or not.


Syntax:
oAsync.Check(cID)
Parameters:
 cID - Unique thread ID to keep track of.
Returns:
 .T. if the thread has finished, otherwise .F.

Count property - holds the current count for the background thread.
Syntax:
oAsync.oEvent.count

RecordError method - populate the error properties with error info


Syntax:
oAsync.RecordError(larr[1],oex.message+[ LineNo: ] + STR(oex.LineNo))

Err property - indicates whether an error occured


Syntax:
oAsync.oEvent.err
Returns:
 .T. if error was encountered, otherwise .F

Err_txt property - last error text


Syntax:
oAsync.oEvent.err_txt
Returns:
 The text of the last error message received

ReturnVal property - holds the name returned from the background thread.
Syntax:
oAsync.oEvent.returnval

StartWebEvent method - Mark the beginning of the background thread.


Syntax:
oAsync.StartWebEvent(cID)
Parameters:
 cID - Unique thread ID to keep track of.
Returns:
 Nothing.
Note: this method is used in the background thread code

CompleteWebEvent method - Mark the completion of the background thread.


Syntax:
oAsync.CompleteWebEvent(cID,cFile)
Parameters:
 cID - Unique thread ID to keep track of.
 cFile - Name of any file that has been produced.
Returns:
 Nothing.
Note: this method is used in the background thread code

StatusWebEvent method - Mark a status point of the background thread.


Syntax:
oAsync.StatusWebEvent(cID,cStatus)
Parameters:
 cID - Unique thread ID to keep track of.
 cStatus - Status of the background thread.
Returns:
 Nothing.
Note: this method is used in the background thread code

AVFPcookie Class

Value - Get the value of a cookie.


Syntax:
(oCookie.value("counter")
Returns:
 The value of the cookie.
Parameters:
 cName - Name of the cookie.
 
Write - Write a value to a cookie.
Syntax:
    oCookie.WRITE("counter",VAL(oRequest.cookies("counter"))+1,"January 1,
2035")
Returns:
    Nothing
Parameters:
 cName - Name of the cookie.
 cValue - Value for the cookie.
 cDate - Expiration date for the cookie.
Note:  See the avfpdemo4 project for a complete example.

Delete - Delete a cookie.


Syntax:
oCookie.DELETE("counter")
Returns:
 Nothing
Parameters:
 cName - name of the cookie.
Note:  See the avfpdemo4 project for a complete example.

AVFPhtml Class

HtmlTable - Evaluate HTML table(s) in an HTML template using the currently open
VFP table.
Syntax:
oHTML. HtmlTable(cTableTag,cHTMLTable,nTotPerPage,lPageNumbers,cBar,lTabl
eRec,nStart,cButton)
Returns:
 String with evaluated table.
Parameters:
 cTableTag -Name of the HTML table (from <htmltablename> in HTML)
 cHTMLtable -HTML table text to be evaluated
 nTotPerPage -Total number of records per page
 lpagenumbers-Include page numbers (need to include nStart and cButton params)
 cBar -Alternating color for HTML table records (for example, #FFFFFF for white)
 lTableRec -Make every record an HTML table (faster writing of HTML tables)
 nStart -Navigational - Page number to start list from, from URL
 cButton -Navigational - First, last, next, previous, from URL
Example:
 lcHTMLout= oHTML.htmlTable('customers',lcHTMLout,5,.F.,'#E5E5E5',.F.,0,'')

MergeText -Evaluate any variable or VFP expression in any text that are contained
within <%= and %>
Syntax: 
 oHTML.MergeText(cStr)
Returns:
 String with evaluated variables and expressions.
Parameters:
 cStr - any character string having the delimeters <%= %> embedded within it.
Example:
 lcHTMLout= oHTML.mergetext(lcHTMLout)

MergeScript -Evaluate any block of codes and expressions in any text that are
contained within <% and %> (code blocks) and <%= and %> (expressions)
Example: 
 lcHTMLfile = 'vfpscript.htm'
 lcHTMLout= FILETOSTR(oProp.HtmlPath+lcHTMLfile)
 lcHTMLout= oHTML.mergescript(lcHTMLout) && app logic is in HTML vfp script
Returns:
 String with evaluated variables and expressions.
Parameters:
 cStr - any character string having the delimeters <%= %> and <% and %> (code
blocks) embedded within it.
Note: Uses CodeBlock by Randy Pearson, Public Domain software: 
http://www.cycla.com/software/codeblock.htm.

HtmlDropdown - create an HTML dropdown list from the currently open table.
Syntax:
 oHTML.HtmlDropDown(cKeyValue,cDisplay,cFormVar,cFirstItem,cSelectedVal,lCo
mplete)
Returns:
 String with HTML dropdown list containing the records of the open table.
Parameters:
 cKeyValue - value that is passed when the record is chosen.  For example, a
product code. 
 cDisplay - value that is displayed in the dropdown list
 cFormVar - name of the dropdown variable that is passed when the form is
submitted
 cFirstItem - first item that is seen.  For example, 'Select a State'.
 cSelectedVal - name of variable that matches key value and will be the selected
value 
 lComplete - if true, include the <select> </select> tags, otherwise do not. 
Example:
 oSession.VALUE("cStates",oHTML.HTMLdropDown('tCursor.stateid',;
 'tCursor.statename','region','Select State/Region',oSession.VALUE("region"),.F.))

GetString - extract a string that exists between any two delimiters 


Syntax
  oHTML.GetString(cStr,cDelim1,cDelim2)
Returns:
 String with that was between the delimiters.
Parameters:
 cStr - string containing delimiters that were passed
 cDelim1 - the first delimiter
 cDelim2 - the second delimiter.
Example:
 lcStr=oHTML.GetString(lcHTML,'<','>')

DumpVars - create a listing of all available intrinsic and AVFP variables.


Syntax:
 oHTML.DumpVars()
Returns:
 String with listing of all variables.
Parameters:
 None
Example:
 oSession.VALUE("cASPvars")=oHTML.DumpVars() 

AVFPhttpupload Class

HttpUpload - do RFC1867 file upload(s) from an HTML form.  


Syntax:
 oUpload.Save(cDir)
Returns:
 number of files successfully uploaded.
Parameters:
 cDir - directory to save files to.
Example:
 lnFiles = oUpload.Save('c:\temp') 
    Additional methods related to HttpUpload:

setchunksize - Set the chunk file transfer size property. Experimental - default
(65000) seems to work best. Use before calling the save method.

setcpusleep - Set the cpu sleep number property. Experimental - default (0) seems
to work best. Use before calling the save method.

setmaxsize - Set the maximum file transfer size property. Use this method to limit the
size of files uploaded from clients.  Use before calling the save method.
oUpload.setmaxsize(5000000)
getelapsedtime - Get the elapsed time of the file transfer.

getfileex - Get the file extension of the uploaded file.

getfilename - Get the name of the uploaded file.

    oUpload.getfilename('FILE1')

    Pass the name of the file variable from the HTML form.
    Returns the file name and extension of the uploaded file.

getfileorig - Get the name of the original file uploaded as named on the client pc.

getfilesize - Get the size of the uploaded file.

getfilestem - Get the file stem of the uploaded file.

getmform - Get a multipart form value.

getpercent -  Get what the current percentage of the upload has been done.

getpid - Get a unique id to be used with the progress indicator feature.

gettotal - Get the total bytes transferred as reported by the multipart form..

gettransfered - Get the total actually transferred from the upload process.

AVFPpdf Class

Start - Output a VFP report to PDF using GhostScript.


Syntax:
oPDF=CREATEOBJECT("PDFrun.Print2PDF")  && Create the EXE server
oPDF.start(lcFile,NVL(oRequest.Form("Company"),""))
Returns:
 A PDF version of the VFP report suitable for displaying on the web.
Parameters:
 cFile - Full path to the VFP report.
 cQuery - Optional parameter to extract specific data.
Note:  You must run DCOMCNFG on PDFrun.Print2PDF prior to use:
1.) Download and install AFPL Ghostscript 8.54 .
2.) Install a PostScript printer driver:  Download the Driver
Download Adobe's self-installing executable PostScript driver, universal
installer version 1.0.6 or later, for Windows 95/98/Me/NT/2000/XP. (You can
browse for other versions of the driver on Adobe's web site.) Save the
downloaded file, winsteng.exe, to a temporary location, such as C:\TEMP.
You will also need a PostScript Printer Description (PPD) file. Use the Generic
Colour PostScript PPD in the zip file defpscol.zip (included in the setup and on
the web). Download and unzip this and extract the enclosed file, defpscol.ppd,
to the same temporary location as you downloaded the driver.
Installing the Driver:
* Find the file winsteng.exe which you downloaded earlier and double-click on
it to run it
* Accept the licence agreement
* Choose the connection type Local Printer (rather than Network Printer)
* When asked to choose a port to connect the printer to, choose FILE: (rather
than COM1:, COM2:, etc.)
* When asked to choose a printer model, you can choose the option Generic
PostScript Printer, but if you  would like to print in colour as well as black and
white, click on the Browse button and browse to the location where you
unpacked defpscol.ppd earlier and choose Generic Colour PostScript
* If asked, don't make this your default printer
* And don't try to print a test page yet
* If asked, say you do wish to configure your printer and check that the default
paper size is set to A4
3.) Run DCOMCNFG on PDFrun.Print2PDF. Under Security for
PDFRun.Print2PDF, add Custom Access and Custom Launch permissions for
the IUSR, IWAM, and ASPNET accounts.
4.) Under the Identity tab for PDFRun.Print2PDF, make sure the Interactive
user is selected.
5.) For more information on using AVFPpdf, see the avfpdemo4 project source
and demo for a complete example.

AVFPproperties Class

Save values to this object to be used throughout the entire application.


Example:
* process the request from the URL
oProp.Action=oRequest.querystring("action")

Action - Store the value from the 'action=' on the query string.

AppName - Store the application's name like 'avfpdemo4'.

AppStartPath - Store the full path of where the application started.

HTMLpath - Store the full path of where the HTML files for the app can be found..

ScriptPath - Store the URL for the application such as 'http://localhost/avfpdemo4'.

SessID - Store the value from the 'sid=' on the query string.

AVFPrequest Class
This class is based on the Request object.  Here are some of it's methods:

QueryString - obtain a value from the URL.


oProp.Action=oRequest.querystring("action")

Form - obtain a value from the HTML form.


IF !EMPTY(oRequest.FORM("txtMailFrom"))
Servervariables - obtain one of the Server variables passed on every request.  Run
oHTML.DumpVars() to get a complete listing.
oProp.ScriptPath=oRequest.servervariables("SCRIPT_NAME")

Cookies - obtain a value from a cookie


IF EMPTY(oRequest.cookies("ActiveVFP"))

AVFPresponse Class
This class is based on the Response object.  Here are some of it's methods:

Redirect - go to a different URL


oResponse.Redirect(lcNewPath)

Authenticate - pop up an authentication box so a user can login using NT or Win2K


accounts.  Once properly authenticated, there will be a value in
orequest.servervariables("AUTH_USER") that you can check on subsequent hits to
decide whether to allow access or not.
oResponse.Buffer = .T.
oResponse.Clear
oResponse.Status = "401 Unauthorized"
oResponse.AddHeader("WWW-Authenticate","BASIC")
oResponse.End

AVFPsession Class
This wrapper class is based on the Session object.

Value - use the Session object


Syntax:                       
 oSession.Value(cVariable,Value)
Returns:
 If only the Variable name is passed, the Value that was stored is returned, otherwise
the second value that's passed is stored.
Parameters:
cVariable - any variable
Value - any value
Example:
 ldDate=oSession.Value("Date")  && retrieve
oSession.Value("Date", DateTime())  && set

AVFPsessiontable Class

Value - mimic the Session object, but, use a DBF for storage
Syntax:                       
 oSessionTable.Value(cVariable,Value)
Returns:
 If only the Variable name is passed, the Value that was stored is returned, otherwise
the second value that's passed is stored.
Parameters:
cVariable - any variable
Value - any value
Example:
 ldDate=oSessionTable.Value("Date")  && retrieve
oSessionTable.Value("Date", DateTime())  && set
Note:
 Useful to overcome limitations of regular sessions that use cookies.  If you
encounter any problems with AVFPsessiontable, you may want to use the
AVFPsession class which is just a wrapper for the regular version. 

SetSessPersist - set how long table sessions will remain on disk.


Syntax:                       
 oSessionTable.SetSessPersist(nLength)
Returns:
 Nothing
Parameters:
 nLength - number of seconds that sessions should persist
Example:
 oSessionTable.SetSessPersist(86400)  && 1 day (default)
Note:
 For busy sites that use the Value method extensively, you probably want to have a
lower timeout value.  For example, oSessionTable.SetSessPersist(5400) && 90
minutes.  Issue this method before Value.  

AVFPsql Class

cSQLCursor - Property contining the name of the local cursor.


Login -
Parameters:
 cLoginStr - The string containing authorization to access the SQL database 
Execute -
Parameters:
 cSQL - The Sql Server SQL statement.
Example:
oSQL = CREATEOBJECT("AVFPsql")
lcLast=NVL(oRequest.Form("lastname"),"")
oSQL.LogIn(['server=AMW\NetSDK;driver={SQL
Server};database=pubs;Trusted_Connection=Yes']) && or connect string ['pubs','sa']
oSQL.cSQLCursor = "tCursor"
oSQL.Execute([SELECT Au_fname as First,Au_lname as Last,City,Contract ]+;
[ FROM Authors ]+;
[ WHERE au_lname like '] +lcLast +[%' order by au_lname] )
 

Other Tools:
SMTP E-Mail with CDO
Send SMTP E-mail using the built-in CDOSYS.dll or CDONTS.dll.  Requires an
available SMTP server that you're authorized to use or that the Microsoft IIS SMTP
service be installed and running.  See the included avfpdemo4 project for a complete
example.
Charts and Graphs with OWC (Office Web Components)
Create dynamic graphs and charts with the free Office Web Components.  OWC is
included with Microsoft Office and FrontPage.  You can also obtain it for free from
this link: http://office.microsoft.com/downloads/2002/owc10.aspx . This is a high
performance way to create charts form a variety of sources.  See the included
avfpdemo4 project for an example. 

FTP and other Internet functions


See Using Win32 functions in Visual FoxPro and
this free FTP class .

Full-text searching and indexing


Check out this class.

Timer that works in a VFP mtdll (thanks to turiya36)


1) go get this .ZIP file from here:
http://download.com.com/3000-2401-889219.html?tag=lst-0-1
2) unzip the .EXE and regsvr32 the associated .DLL
regsvr32.exe ccrpTmr.dll
3) Build the following code as a MTDLL:
DEFINE CLASS TimerTest AS CUSTOM OLEPUBLIC
     oTimerControl = .NULL.
     oTimerEventHandler = .NULL.
     PROCEDURE INIT
          ** Create the timer object
          THIS.oTimerControl = CREATEOBJECT( "ccrpTimers.ccrpTimer" )
          ** Create the event handler
          THIS.oTimerEventHandler = CREATEOBJECT( "TimerEventHandler" )
          ** Attach the eventhandler to the timer control
          EVENTHANDLER( THIS.oTimerControl, THIS.oTimerEventHandler )
          ** Set the timer properties
          ** As soon as your set enabled to .T., the timer will begin functioning
          ** Event type, 0 - one shot timer event, 1 - Periodic timer events
          THIS.oTimerControl.EventType = 1
          THIS.oTimerControl.INTERVAL = 1000
          THIS.oTimerControl.ENABLED = .T.
     ENDPROC
ENDDEFINE
** Replace the path in the IMPLEMENTS line with the path where you  installed
ccrptmr.dll
DEFINE CLASS TimerEventHandler AS SESSION
     IMPLEMENTS __ccrpTimer IN "c:\ccrp\ccrptmr.dll"
     PROCEDURE __ccrpTimer_Timer( Milliseconds AS NUMBER ) AS VOID ;
               HELPSTRING "Event that fires whenever [Interval] milliseconds elapses."
          ** Your timer event code goes here
          IF !DIRECTORY( "c:\temp\" )
               MD c:\temp          ENDIF
          =STRTOFILE( "", "c:\temp\" + ALLTRIM( STR( SECONDS(), 12, 2 )) + ".txt" )
     ENDPROC
ENDDEFINE
4) Instantiate the class:
oCom = CREATEOBJECT( "TimerTest.TimerTest" )
That's it!  Your timer events will now function correctly in a VFP MTDLL. 
One final thing to remember.  Before you release the object (in the case of above,
oCom) you must set the enabled property of the timer control to .F. like this:
oCom.oTimerControl.Enabled = .F.
Otherwise VFP will crash with a C00005 error.
 

Copyright © 2009 dotComSolution.  All Rights Reserved. 

You might also like