Jump to content

ActiveVFP

From Wikipedia, the free encyclopedia
AVFP
Paradigmobject-oriented,procedural,4-GL
DeveloperVFP Community
First appeared2001;23 years ago(2001)
Stable release
6.03 / January 29, 2013;11 years ago(2013-01-29)
Typing disciplineDynamic,weak
Implementation languageVisual FoxPro 9 SP2
OSWindows
LicenseMIT
Filename extensionsCommon extensions
.avfp
Other extensions
extensionless
Websiteactivevfp.codeplex.com

ActiveVFP(also known asAVFP) is aserver-side scriptingframework designed forWeb developmentto producedynamic Web pages.Similar toPHP,but using the nativeVisual Foxpro (VFP) language and database(or otherdatabaseslikeMicrosoft SQLandMySQL), ActiveVFP can also be used inModel-View-Controller (MVC)web applications as well asRESTful API.ActiveVFP is completely free andopen sourceand 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 atactivevfp.codeplex.comand serves as the formal reference to ActiveVFP. ActiveVFP isfree softwarereleased under theMIT License.

ActiveVFP is unique among server-side web languages and frameworks because it has a database and database functionality built into the language.

Syntax

[edit]

ActiveVFP uses the native Visual Foxpro language as it exists in the latest version produced by Microsoft, Visual FoxPro 9 SP2. Themulti-threadedVFP runtime, vfp9t.dll, is used instead of the regular desktop version of the VFP runtime.[1]

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.[2]

Like PHP, ActiveVFP takes advantage of automaticmemory Garbage Collection (GC)andDynamic/Weak Typing,[3]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

[edit]
  • VFP code embedded inHTMLcode to open table and list records
<!DOCTYPE html>
<html>
<head>
<metacharset="utf-8">
<title>VFPcodeinHTML</title>
...
<%
*Settings
lnTotPerPage=10
lnpagenumbers=5
lnStart=VAL(oRequest.querystring("page"))
lcButton=oRequest.querystring("nav")
*sql
SELE*FROMCustomerINTOCURSORtCursor
*createpagenumbers
START=0
lnPageMax=0
lnPageBegin=0
lnRowCount=RECCOUNT()
SETPROCtooProp.AppStartPath+'prg\pages' ADDITIVE
lcPages=pages(lnTotPerPage,lnpagenumbers,lnStart,lcButton,lnRowCount)
%>
...
<%FORlnX=lnPageBeginTOlnPageMax
IFlnX<=lnRowCount
GOTOlnX%>
<tr>
<tdwidth="40%"><fontface="helvetica, arial"size="2">
<ahhref="<%=JustPath(oProp.ScriptPath)+[/detail.avfp?cust_id=]+;
ALLTRIM(cust_id)%>"><%=tCursor.company%></a></font></td>
<tdwidth="36%"><fontface="helvetica, arial"size="2">
<%=tCursor.Contact%></font></td>
<tdwidth="24%"><fontface="helvetica, arial"size="2"color="#000000">
<%=tCursor.Title%></font></td>
</tr>
<%ENDIF
ENDFOR%>
...
<%=lcPages%>
  • VFP Controller code for an MVC web application
* customers.prg -Customers Controller
* * bypasses Main.prg and.AVFP script code
*
DEFINECLASScustomersController AS restController
*
PROCEDUREopenData
SELECT0
USE(THIS.homeFolder +"customers.dbf") ALIAScustomers
ENDPROC

PROCEDUREinfoAction&& GET www.hostname.com/app/customers/info
RETURN"homeFolder: <b>"+THIS.homeFolder +"</b>"
ENDPROC

PROCEDUREgetAction&& GET www.hostname.com/app/customers/<id>
LOCALcCustId
cCustId=THIS.Params[1]
THIS.openData()
SELECTCUSTOMERS
LOCATEFOR custId = cCustId
IFFOUND()
LOCALcJSON
**USE mydbf &&test error
*quick and dirty JSON
cJSON= [{"custId":"] + RTRIM(custId) + [","custName":"] + RTRIM(custName) + [",] +;
["custStat":"] + RTRIM(custStat) + ["}]
RETURNcJSON
ENDIF
ENDPROC

PROCEDURElistAction&& GET www.hostname.com/app/customers/
LOCALcHTML
cHTML=""
*oEmp=newOBJECT('schedbizobj','c:\avfp5.61Demo\prg\utiltest2.prg')
SETPROC tosubstr(oProp.AppStartPath,1,AT([\],oProp.AppStartPath,2))+'prg\AVFPutilities'ADDITIVE&& Make sure you use ADDITIVE or bad things happen!
THIS.openData()
SELECTCUSTOMERS
cHTML= oHTML.mergescript(FILETOSTR(substr(oProp.AppStartPath,1,AT([\],oProp.AppStartPath,2))+'viewtest.avfp'))
RETURNcHTML
ENDPROC

PROCEDUREhelloworld&& custom method (&& GET www.hostname.com/app/customers/helloworld/)
LOCALcHTML
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'))
RETURNcHTML
ENDPROC

PROCEDUREgetemployees&& custom method (&& GET www.hostname.com/app/customers/getemployee/<id>

oJSON=NEWOBJECT('json','json.prg')

SETPATH TO oProp.AppStartPath+'data\AVFPdemo41\'

selecte.emp_id as id, e.first_Name as firstName, e.last_Name as lastName, e.title as title, [images/Emps/]+e.pictureas picture,count(r.emp_id) as reportCount;
fromemployee e left join employee r onVAL(r.reports_to) =VAL(e.emp_id);
INTOCursorSearchResults;
groupby e.last_Name,e.emp_id, e.first_Name,e.title, e.picture;
orderby 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

[edit]
[edit]