ActiveVFP Documentation
Version 6.03/5.53
Updated 1/30/2013

Introduction
    Requirements
    Support
    Free Add-on Downloads
    Basics
    Donations
Setup
VFP Scripting
    <%= %> Expressions and Variables
    <% %> Scripts
    Centralizing FoxPro code - Custom or Existing Functions, Procedures, Libraries

Installation and Distribution
Networked DBFs
MS SQL, MySQL, and other databases
Network Setup
Reporting/Printing
Debugging
Changing the extension scriptmap
HTML: Special Characters
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:

Notepad or equivalent text editor(purchase of Visual Foxpro optional, WYSIWYG HTML editor like Expression optional but recommended)
ASP.NET and ASP enabled
Reg-Free requires IIS 6 or higher

64 Bit
Windows OS/hardware requires enabling 32 Bit operation for IIS
via IIS Manager (Application Pools/DefaultAppPool/Advanced Settings/Set Enable 32-bit applications to True) or issue the following command from Run or the CMD line(you must Run as Administrator)
cscript %SYSTEMDRIVE%\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 1

 

Support:

http://activevfp.codeplex.com/Thread/List.aspx  (Discussion Forum)

Downloads:

jqGrid
http://jqgrid.com/

jQueryMobile
http://jquerymobile.com/
 
Office Web Components(OWC) for Web Charting -
http://www.microsoft.com/en-us/download/details.aspx?id=22276


PocketFox - DBF Manager for those that don't have the Microsoft FoxPro IDE
http://www.pocketfox.org/

IIS Express 7.5 Web Server - works on Windows XP and all Starter and Home Basic versions of Windows
http://www.microsoft.com/en-us/download/details.aspx?id=1038
 

Basics:

Browser<-->
(AJAX,JSON,etc)

IIS web server 

<-->

ASP.NET
(ISAPI dll)

<--->

ActiveVFP.dll (mtdll)

<--->main.prg
<--->HTML templates
<--->background threads
<-->images
<--->E-mail templates
<--->DB

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

main.prg - this is where your application logic can go including pre-processing and post-processing. Alternatively, you could place most of your application code within the AVFP scripts/HTML templates themselves. 

AVFP Scripts (.avfp), HTML and e-mail templates - this is where you control the look and feel of the application (the "Views" in MVC speak).  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.

AVFP scripts/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 at runtime.
For example,  Total Customers=<%=reccount()%>  or 
<%=tCursor.Contact%>

<% %> Scripts
Place any VFP code within the HTML templates by putting it between the standard <% %> (alligator) delimiters.  The code here will be dynamically compiled and executed at runtime.  Here are some examples:

<%IF reccount() > 0 %>
<p>there are records!</p>
<%else%>
<p>there are no records for you!</p>
<%endif%>

<% *sql
SELE * FROM Customer INTO CURSOR tCursor

*create page numbers
START=0
lnPageMax = 0
lnPageBegin = 0
lnRowCount = RECCOUNT()
SET PROC to oProp.AppStartPath+'prg\pages' ADDITIVE && Make sure you use ADDITIVE or bad things happen!
lcPages= pages(lnTotPerPage,lnpagenumbers,lnStart,lcButton,lnRowCount)
%>

<% FOR lnX = lnPageBegin TO lnPageMax
           IF lnX <= lnRowCount
              GOTO lnX %>
             <tr>
                  <td width="40%"><font face="helvetica, arial" size="2"><a href="<%=oProp.ScriptPath +[?action=detail&cust_id=]+ALLTRIM(cust_id)%>">
<%=tCursor.company%></a></font></td>
                  <td width="36%"><font face="helvetica, arial" size="2">
<%=tCursor.Contact%></font></td>
                  <td width="24%"><font face="helvetica, arial" size="2" color="#000000">
<%=tCursor.Title %></font></td>
            </tr>
<% ENDIF
ENDFOR %>

<% IF EMPTY(oRequest.servervariables("AUTH_USER"))
            oResponse.BUFFER = .T.
            oResponse.CLEAR
            oResponse.STATUS = "401 Unauthorized"
            oResponse.AddHeader("WWW-Authenticate","BASIC")
            oResponse.END %>
<% ELSE %>
            Congratulations! You're authenticated.
<%ENDIF %>


Want even less code in your HTML?   Use the following as an alternative to producing tables:
From your code-behind .prg or main.prg:
SELE * FROM Customer INTO CURSOR tCursor
lcHTMLfile = 'custlist.htm' && html template
lcHTMLout= FILETOSTR(oProp.HtmlPath+lcHTMLfile)
lcHTMLout= oHTML.htmlTable('customers',lcHTMLout,10,5,'#E5E5E5',.F.;
                            ,VAL(oRequest.querystring("page")),oRequest.querystring("nav"))
lcHTMLout= oHTML.mergetext(lcHTMLout)

From your HTML template include the <tablename> </tablename> tags.
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.company%> <%=tCursor.Contact%> <%= tCursor.Title %>

</customers>
You may place as many tables to be evaluated as desired on an HTML page.

Centralizing Foxpro code for re-use:

Custom or existing VFP Functions, Procedures, Methods can use the traditional ways to centralize VFP code:

SET PROC TO  ... ADDITIVE,

CREATEOBJECT,

etc  (see examples).  These objects will be cached by IIS and perform very fast.  If you will make changes to these libraries, you must release them from memory using their release commands.  Otherwise, IIS won't let you change these objects unless you re-cycle the App or IIS.

Use CompileIfNew to automate compilation of changes you've made to source. 
SET PROC to 'c:\avfp6\prg\compileifnew' additive
RETURN compileifnew('avfputilities')

Here are some examples:

In any .avfp page (AVFP 6.0) or .htm page ( 5.53):

<% oAA=newOBJECT('schedbizobj','c:\avfp6.0Demo\prg\utiltest2.prg') %>

<%=oAA.test3('news')%>

<% oAA=null

CLEAR CLASS ('schedbizobj')

CLEAR PROGRAM ('prg\utiltest2.prg')

%>

OR

<% SET PROC to 'c:\avfp6.0Demo\prg\utiltest' ADDITIVE %>

<%= test3('new')%>

<% RELEASE PROCEDURE 'c:\avfp6.0Demo\prg\utiltest'%>

 

Alternatively, in main.prg, at the top of the CASE statement:

oAA=newOBJECT('schedbizobj','c:\avfp6.0Demo\prg\utiltest2.prg')

OR

SET PROC to 'c:\avfp6.0Demo\prg\utiltest' ADDITIVE

AND, at the bottom of the CASE statement:

oAA=null

CLEAR CLASS ('schedbizobj')

CLEAR PROGRAM ('prg\utiltest2.prg')

 

OR

RELEASE PROCEDURE 'c:\avfp6.0Demo\prg\utiltest'

Alternative Solution 1:  Functions and Procedures that are in development or may change often can simply be placed at the bottom of Main.prg to be available to all scripts. (IOW, main.prg is your new Function/Procedure Library)

Alternative Solution 2:  If your Functions/Procedures are in their own files, containing only the one Function/Procedure, use ExecScript to run them on the fly from your scripts without caching in IIS and therefore not locking them:

lcRetVal = EXECSCRIPT(FILETOSTR(oProp.AppStartPath+'\prg\myexternalfunc.prg'))

You may change the Functions and Procedures used in these techniques as needed.

 Installation and Distribution:

Try AVFP at any cheap hosting site that provides Full-Trust. No COM registration required.
ActiveVFP 6.03 - Works on local IIS, WinHost, Discount ASP.NET, Arvixe, SoftSys, many others.
ActiveVFP 5.53 - Works on local IIS, GoDaddy, WinHost, Discount ASP.NET, Arvixe, SoftSys, many others.  
So, for $5/month you can host vfp web apps on a shared web server!!!

Installing on your own IIS web server:

1.) IIS 6 (Windows 2003 Server) or higher is supported unless IIS Express is used (which works on Win XP and all Basic and Starter Windows versions). 

2.) Unzip the ActiveVFP 6.0 zip file or the AVFP 5.53 (for ASP.NET 2.0) zip file to its own folder.

3.)  IIS must be installed.  If it's not or you're not sure: From 'Control Panel\Install Programs', choose 'Turn Windows features on or off'. Choose 'Internet Information Services'. Press OK.

4.) ASP.NET and ASP must be enabled from Control Panel\Install Programs\Turn Windows Features on.  From Control Panel, Expand Internet Information Services, then World Wide Web Services, then Application Development Features.  Select ASP.net and ASP and then click OK.

5.) If you're running a 64-bit version of Windows you must enable 32 bit apps via IIS Manager (Application Pools/DefaultAppPool/Advanced Settings/Set Enable 32-bit applications to True) or issue the following command from Run or the CMD line(you must Run as Administrator)

%systemroot%\system32\inetsrv\APPCMD set apppool /apppool.name: "DefaultAppPool" /enable32bitapponwin64:true

OR

cscript %SYSTEMDRIVE%\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 1 

6.) In IIS Manager create an Application (Windows 7, Vista, or above)  or Virtual Directory (Windows 2003 Server) over the folder by right-clicking Default Web Site and taking the appropriate option.  If asked, give Write and Script permissions.  

7.) Optionally, apply write privileges in IIS Manager to the Data directory and the Temp directory if you intend to update data.

8.) To test from a web browser: http://localhost/<the virtual directory>/default.aspx (for example, http://localhost/regfreetest/default.aspx) for AVFP version  5.53 or http://localhost/<the virtual directory>/default.avfp for AVFP version 6.0

9.) To develop a new ActiveVFP web application, just create a file in Notepad or MS Expression saved with an .avfp extension (6.0) or as one of the HTML templates ( 5.53).  For example:

hello world from
 <%=version()%>
<%=date()%>

Save as helloworld.avfp (6.0) and call from any browser:

http://localhost/demo/helloworld.avfp       (6.0)

http://localhost/demo/default.aspx?action=helloworld    ( 5.53)

 NOTE:  /prg/main.prg is where pre-processing and post processing occurs.  It can optionally be used when needed.

10.)  See the demo code.

 

Requirements for ActiveVFP 6:
IIS 7.5, Windows Server 2008 R2 and Windows 7 (Home Premium, Professional, Enterprise and Ultimate editions)or above
IIS 7.0, Windows Server 2008 and Windows Vista (Home Premium, Business, Enterprise and Ultimate editions)
Use AVFP5.53(for ASP.NET 2.0) for IIS 6
IIS Express 7.5 will work with ActiveVFP on Windows XP and Home and Starter Versions of Windows.

ASP.NET 2.0 or above
Integrated pipeline mode(the default mode)
Full Trust

ActiveVFP 6 Notes:
Tested successfully on Windows 7 Pro 64-bit(IIS7.5) and VISTA Home Premium 32-bit(IIS 7)
Some cheap web hosts that support Full Trust with ASP.NET 2.0: Discount ASP.NET, WinHost, Arvixe  (all are $5/month)
I couldn't get this version to work with GoDaddy (use AVFP5.53(for ASP.NET 1.1) for GoDaddy).

Networked DBFs and SQL setup:

To access dbf data across the network (not on the local machine) or to use SQL Server, MySQL or other backend, you must use Impersonation of an account that has the proper rights to the network data. 

The preferred way to do this is to configure IIS Application Pools in IIS 6 and above to impersonate an account that has the proper rights to the network data (alternatively , COM + could be used for the same purpose).

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 in your vfp code, and calling the method that does the REPORT FORM from your vfp code.

NOTE: The GhostScript  file, gsdll32.dll, is now included with AVFP, as is the project source  for PDFRun.exe � all in the Reports directory.

1.)  Register PDFRun.exe <Full path of pdfrun.exe file> /RegServer
(e.g. C:\Program Files\dotComSolution\AVFPdemo6\pdfrun.exe /RegServer)
OR just compile the PDFRun project
2.) 
Run DCOMCNFG (For Win 7 or above use mmc comexp.msc /32). Find PDFrun.Print2PDF. Under the Security tab for PDFRun.Print2PDF, add Custom Access and Custom Launch permissions for the IUSR, IWAM, and ASPNET accounts. Under the Identity tab for PDFRun.Print2PDF, make sure the Interactive user is selected.
3.) 
Install one of these Printer Drivers from the regular Windows �Add Printer� panel according to OS version:
Xerox Phaser 6120 PS (Win 7 or above)
Xerox Phaser 1235 PS (Vista)
Apple Color LW 12/660 PS (Win 2003 Server)
4.) 
In PDF.avfp (or PDF.htm), you'll need to add this property to the oPDF object like:

<%

oPDF=CREATEOBJECT("pdfrun.print2pdf")

if isnull(oPDF)

       return .f.

endif

oPDF.cPSColorPrinter ="Xerox Phaser 6120 PS"         && or whichever driver installed

...

Debugging

There is a debugger utility in the included Demo app that dumps all the ActiveVFP variables to the bottom of the screen.  Just turn it on on the default page (upper right-hand corner) or use this use this url:
http://localhost/6.0test/sessionlist.avfp?debug=on
and
http://localhost/6.0test/sessionlist.avfp?debug=off to turn it off.
You can also always use the handy STRTOFILE command to quickly output variables to a text file for inspection like
STRTOFILE(myVar,'c:\temp\myVar.txt') or simply output variables directly to the screen like <%=myVariable%>.

For more robust debugging, use Visual Studio and the regular FoxPro debugger as follows (only works for AVFP  5.53):
1.) Download the source files from http://activevfp.codeplex.com

2.) Open Foxpro (Run as Administrator) and cd to C:\yourdirectory\prg

3.) Open Visual Studio (Run as Administrator)

4.) In Visual Studio, from the File Menu, choose 'Open Web Site' and then 'File System'

5.) Still in Visual Studio, open the ActiveVFP directory and click on debug.aspx .

6.) Press F5 (which is Debug/Start Debugging)

7.) You should now see the Foxpro debugger window open.
Now you can step into Foxpro to examine the inner workings of ActiveVFP!


Changing the extension scriptmap (AVFP6.0 only)

1.) Rename all files with .avfp to the desired extension:  REN *.avfp *.mynewext

2.) In Web.Config, find this section:
<handlers>
<add verb="*" path="*.avfp"
name="AVFPHandler"
type="AVFPHandler"/>
</handlers>

3.) Rename .avfp to .mynewext as follows:
<handlers>
<add verb="*" path="*.mynewext"
name="AVFPHandler"
type="AVFPHandler"/>
</handlers>

4.) Now find this section:
<defaultDocument>
<files>
<clear/>
<add value="default.avfp" />
</files>
</defaultDocument>

5.) Change to:
<defaultDocument>
<files>
<clear/>
<add value="default.mynewext" />
</files>
</defaultDocument>

6.) Run the Demo starting with Default.mynewext

HTML: Special Characters

* thanks to "loadingpower"

Using certain special characters from some non-English languages may lead to problems. Here's a solution:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>

Note that the charset must be the same used on visual foxpro

You can check on this way <%= CPCURRENT() %><br>

Using this all special chars will work, case you don't put this metatag, all characters will be passed as iso-8859 and the avfp will receive other chars than the ones you see on the page.

Cedilha up <%= '�'+'a' %><br>
Cedilha low <%= '�' %><br>
Code Page <%= CPCURRENT() %><br>
Cedilha up <%= ASC('�') %><br>
Cedilha low <%= ASC('�') %><br>


Everthing is solved with the inclusion off the head tag,


ActiveVFP Classes, Methods, Properties:

AVFPasync Class (WebThreads.prg)
Note:  WebThreads now uses CreateThreadObject from the vfp2c32.fll library (project is at VFPX).
See the included DoCount.prg

--------------------------------------------------

Properties
lSilent = .f. (default) .t.= run the thread with no update page, defaults to having an update page
nRecExpire = 5400 (default) how long to keep Event records. (An Event table is created in the Temp folder).

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

Other:  Launch a thread with no HTML interface:
oAsync=CREATEOBJECT("ThreadManager") &&put your own code to run as a background thread in whatever.prg
oAsync.lSilent = .t. && just run the thread with no update page, defaults to having an update page
oAsync.nRecExpire = 600 && how long to keep Event records
cEventID=oAsync.CreateThread("docount","----- Hello! I am running VFP code,----- on a background thread,----- while sending you status updates,...Your form value is: wee 555")

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 avfpdemo5 project for a complete example.

Delete - Delete a cookie.
Syntax:
oCookie.DELETE("counter")
Returns:

 Nothing
Parameters:

 cName - name of the cookie.
Note:  See the avfpdemo5 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,lTableRec,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,lComplete)
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

INSTRUCTIONS:

NOTE: The GhostScript  file, gsdll32.dll, is now included with AVFP, as is the project source  for PDFRun.exe � all in the Reports directory.

1.)  Register PDFRun.exe <Full path of pdfrun.exe file> /RegServer
(e.g. C:\Program Files\dotComSolution\AVFPdemo6\pdfrun.exe /RegServer)
OR just compile the PDFRun project
2.) 
Run DCOMCNFG (For Win 7 or above use mmc comexp.msc /32). Find PDFrun.Print2PDF. Under the Security tab for PDFRun.Print2PDF, add Custom Access and Custom Launch permissions for the IUSR, IWAM, and ASPNET accounts. Under the Identity tab for PDFRun.Print2PDF, make sure the Interactive user is selected.
3.) 
Install one of these Printer Drivers from the regular Windows �Add Printer� panel according to OS version:
Xerox Phaser 6120 PS (Win 7 or above)
Xerox Phaser 1235 PS (Vista)
Apple Color LW 12/660 PS (Win 2003 Server)
4.) 
In PDF.avfp (or PDF.htm), you'll need to add this property to the oPDF object like:

<%

oPDF=CREATEOBJECT("pdfrun.print2pdf")

if isnull(oPDF)

       return .f.

endif

oPDF.cPSColorPrinter ="Xerox Phaser 6120 PS"         && or whichever driver installed

...

Method
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.

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 'avfpdemo5'.

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/avfpdemo5'.

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.  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 avfpdemo5 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 avfpdemo5 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.


A Note of Thanks
:

ActiveVFP has always been a community effort.
Thanks to the following FoxPro giants for code and/or ideas that has made AVFP what it is today:

Calvin Hsia
Brian Marquis
Pandelis Tiritas
Rick Strahl
Craig Boyd
Randy Pearson
Maurice De Beijer
Paul James
Ed Rauh
Victor Espina
Christian Ehlscheid

If you examine the source code for ActiveVFP or visit http://activevfp.codeplex.com you're bound to come across some of their code or influences.


Donations:

Donations are accepted.
Click here to donate to help support ActiveVFP and Open Source VFP projects.


Thank you for your support!
 

Copyright 2013 theTechConsult.com.  All Rights Reserved.