ActiveVFP (also known as AVFP) is a
server-side scripting
Server-side scripting is a technique used in web development which involves employing scripts on a web server which produces a response customized for each user's (client's) request to the website. The alternative is for the web server itself ...
framework designed for
Web development
Web development is the work involved in developing a website for the Internet (World Wide Web) or an intranet (a private network). Web development can range from developing a simple single static page of plain text to complex web application ...
to produce
dynamic Web pages. Similar to
PHP
PHP is a General-purpose programming language, general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementati ...
, but using the native
Visual Foxpro (VFP) language and database (or other
database
In computing, a database is an organized collection of data stored and accessed electronically. Small databases can be stored on a file system, while large databases are hosted on computer clusters or cloud storage. The design of databases spa ...
s like
Microsoft SQL
Microsoft SQL Server is a relational database management system developed by Microsoft. As a database server, it is a software product with the primary function of storing and retrieving data as requested by other software applications—which ma ...
and
MySQL
MySQL () is an open-source relational database management system (RDBMS). Its name is a combination of "My", the name of co-founder Michael Widenius's daughter My, and "SQL", the acronym for Structured Query Language. A relational database ...
), ActiveVFP can also be used in
Model-View-Controller (MVC) web applications as well as
RESTful API. ActiveVFP is completely free and
open source
Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use the source code, design documents, or content of the product. The open-source model is a decentralized sof ...
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
Free software or libre software is computer software distributed under terms that allow users to run the software for any purpose as well as to study, change, and distribute it and any adapted versions. Free software is a matter of liberty, ...
released under the
MIT License
The MIT License is a permissive free software license originating at the Massachusetts Institute of Technology (MIT) in the late 1980s. As a permissive license, it puts only very limited restriction on reuse and has, therefore, high license co ...
.
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 (and all of the objects that have been available in Classic Active Server Pages (ASP)). 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 (GC) and
Dynamic/Weak Typing,
Windows Web Scripting Comparison
/ref> boosting programmer productivity.
In addition to “scripting” mode, ActiveVFP offers Model-View-Controller (MVC) 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 embedded in HTML
The HyperText Markup Language or HTML is the standard markup language for documents designed to be displayed in a web browser. It can be assisted by technologies such as Cascading Style Sheets (CSS) and scripting languages such as JavaScri ...
code to open table and list records''
VFP code in HTML
...
<%
*Settings
lnTotPerPage =10
lnpagenumbers =5
lnStart=VAL(oRequest.querystring("page"))
lcButton=oRequest.querystring("nav")
*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(lnTotPerPage,lnpagenumbers,lnStart,lcButton,lnRowCount)
%>
...
<% FOR lnX = lnPageBegin TO lnPageMax
IF lnX <= lnRowCount
GOTO lnX %>
detail.avfp?cust_id=;
ALLTRIM(cust_id)%>"><%=tCursor.company%> |
<%=tCursor.Contact%> |
<%=tCursor.Title %> |
<% ENDIF
ENDFOR %>
...
<%= lcPages %>
* ''VFP Controller code for an MVC web application''
* customers.prg -Customers Controller
* * bypasses Main.prg and .AVFP script code
*
DEFINE CLASS customersController AS restController
*
PROCEDURE openData
SELECT 0
USE (THIS.homeFolder + "customers.dbf") 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('schedbizobj','c:\avfp5.61Demo\prg\utiltest2.prg')
SET PROC to substr(oProp.AppStartPath,1,AT( oProp.AppStartPath,2))+'prg\AVFPutilities' ADDITIVE && Make sure you use ADDITIVE or bad things happen!
THIS.openData()
SELECT CUSTOMERS
cHTML= oHTML.mergescript(FILETOSTR(substr(oProp.AppStartPath,1,AT( oProp.AppStartPath,2))+'viewtest.avfp'))
RETURN cHTML
ENDPROC
PROCEDURE helloworld && custom method (&& GET www.hostname.com/app/customers/helloworld/)
LOCAL cHTML
cHTML = ""
*USE mydbf
*SET PROC to substr(oProp.AppStartPath,1,AT( oProp.AppStartPath,2))+'prg\AVFPutilities' ADDITIVE && Make sure you use ADDITIVE or bad things happen!
cHTML= oHTML.mergescript(FILETOSTR(substr(oProp.AppStartPath,1,AT( oProp.AppStartPath,2))+'hello.avfp'))
RETURN cHTML
ENDPROC
PROCEDURE getemployees && custom method (&& GET www.hostname.com/app/customers/getemployee/
oJSON=NEWOBJECT('json','json.prg')
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, mages/Emps/e.picture as picture,count(r.emp_id) as reportCount ;
from employee e left join employee r on VAL(r.reports_to) = VAL(e.emp_id) ;
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(oJSON.stringify('SearchResults'))
oResponse.Flush
lcHTMLout=[]
ENDPROC
************************************************************************
ENDDEFINE
References
External links
*
{{DEFAULTSORT:ActiveVFP
Fourth-generation programming languages
Data-centric programming languages
Object-oriented programming languages
XBase programming language family
Procedural programming languages
Microsoft development tools
Microsoft database software
Free compilers and interpreters
Scripting languages
Dynamically typed programming languages
High-level programming languages
Class-based programming languages
Web frameworks
Software using the MIT license