ActiveVFP


ActiveVFP is a server-side scripting framework designed for Web development to produce dynamic Web pages. Similar to PHP, but using the native Visual Foxpro language and database, ActiveVFP can also be used in Model-View-Controller web applications as well as RESTful API. ActiveVFP is completely free and open source and does not require the purchase of Microsoft Visual FoxPro or any additional software.
ActiveVFP was originally created in 2001. The main implementation of ActiveVFP is now produced by the Foxpro Community at and serves as the formal reference to ActiveVFP. ActiveVFP is free software released under the MIT License.
ActiveVFP is unique among server-side web languages and frameworks because it has a database and database functionality built into the language.

Syntax

ActiveVFP uses the native Visual Foxpro language as it exists in the latest version produced by Microsoft, Visual FoxPro 9 SP2. The multi-threaded VFP runtime, vfp9t.dll, is used instead of the regular desktop version of the VFP runtime.
Using ActiveVFP, the VFP compiler only executes VFP code within its delimiters. Anything outside its delimiters is not processed by VFP. The most common delimiters are ASP-style short forms <% or <%= and %>. <% %> executes a FoxPro code block and <%= %> prints the variable out immediately. The purpose of all these delimiters is to separate VFP code from non-VFP code, including HTML.
The main objects available to ActiveVFP for web programming are: oRequest, oResponse, and oSession. These objects are used entirely within Visual FoxPro to accomplish web programming with FoxPro.
The FoxPro language contains commands quite similar to other programming languages such as Basic. Loops include do, if, while, for, else commands in a usage easily understood by anyone familiar with other programming languages. Commands take the form of "command" and "endcommand". The language also has extensive database manipulation and indexing commands.
Like PHP, ActiveVFP takes advantage of automatic memory Garbage Collection and Dynamic/Weak Typing, boosting programmer productivity.
In addition to “scripting” mode, ActiveVFP offers Model-View-Controller design as well. The Controller consists of FoxPro class code located in a Foxpro.prg file. Output can consist of.avfp views, JSON, and others, similar to other modern MVC implementations. The Model can be DBF files or other back end databases.

Examples






VFP code in HTML
...
<%
  • Settings
lnTotPerPage =10
lnpagenumbers =5
lnStart=VAL
lcButton=oRequest.querystring
  • 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
lcPages= pages
%>
...
<% FOR lnX = lnPageBegin TO lnPageMax
IF lnX <= lnRowCount
GOTO lnX %>


ALLTRIM%>"><%=tCursor.company%>


<%=tCursor.Contact%>


<%=tCursor.Title %>


<% ENDIF
ENDFOR %>
...
<%= lcPages %>


  • customers.prg -Customers Controller
  • * bypasses Main.prg and.AVFP script code
DEFINE CLASS customersController AS restController
*
PROCEDURE openData
SELECT 0
USE ALIAS customers
ENDPROC
PROCEDURE infoAction && GET www.hostname.com/app/customers/info
RETURN "homeFolder: " + THIS.homeFolder + ""
ENDPROC
PROCEDURE getAction && GET www.hostname.com/app/customers/
LOCAL cCustId
cCustId = THIS.Params
THIS.openData
SELECT CUSTOMERS
LOCATE FOR custId = cCustId
IF FOUND
LOCAL cJSON
**USE mydbf &&test error
*quick and dirty JSON
cJSON =
RETURN cJSON
ENDIF
ENDPROC
PROCEDURE listAction && GET www.hostname.com/app/customers/
LOCAL cHTML
cHTML = ""
*oEmp=newOBJECT
SET PROC to substr+'prg\AVFPutilities' ADDITIVE && Make sure you use ADDITIVE or bad things happen!
THIS.openData
SELECT CUSTOMERS
cHTML= oHTML.mergescript)
RETURN cHTML
ENDPROC
PROCEDURE helloworld && custom method
LOCAL cHTML
cHTML = ""
*USE mydbf
*SET PROC to substr+'prg\AVFPutilities' ADDITIVE && Make sure you use ADDITIVE or bad things happen!
cHTML= oHTML.mergescript)
RETURN cHTML
ENDPROC
PROCEDURE getemployees && custom method

SET PATH TO oProp.AppStartPath+'data\AVFPdemo41\'
select e.emp_id as id, e.first_Name as firstName, e.last_Name as lastName, e.title as title, +e.picture as picture,count as reportCount ;
from employee e left join employee r on VAL = VAL ;
INTO Cursor SearchResults;
group by e.last_Name,e.emp_id, e.first_Name,e.title, e.picture ;
order by e.last_Name,e.first_Name
oJSON.keyforcursors="items"
* send JSON data and properties back
oResponse.ContentType = "application/json;charset=utf-8"
oResponse.Write
oResponse.Flush
lcHTMLout=
ENDPROC
  • ***********************************************************************
ENDDEFINE