ActiveVFP Documentation
ActiveVFP Documentation
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)
Basics:
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.
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.
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.
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:
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)
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>
</customers>
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)
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.
Count property - holds the current count for the background thread.
Syntax:
oAsync.oEvent.count
ReturnVal property - holds the name returned from the background thread.
Syntax:
oAsync.oEvent.returnval
AVFPcookie Class
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.))
AVFPhttpupload Class
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.
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.
getpercent - Get what the current percentage of the upload has been done.
gettotal - Get the total bytes transferred as reported by the multipart form..
gettransfered - Get the total actually transferred from the upload process.
AVFPpdf Class
AVFPproperties Class
Action - Store the value from the 'action=' on the query string.
HTMLpath - Store the full path of where the HTML files for the app can be found..
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:
AVFPresponse Class
This class is based on the Response object. Here are some of it's methods:
AVFPsession Class
This wrapper class is based on the Session object.
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.
AVFPsql Class
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.