ActiveVFP

Last updated
AVFP
ActiveVFPlogo2.png
Paradigm object-oriented, procedural, 4-GL
Developer VFP Community
First appeared2001;20 years ago (2001)
Stable release
6.03 / January 29, 2013;8 years ago (2013-01-29)
Typing discipline Dynamic, weak
Implementation language Visual FoxPro 9 SP2
OS Windows
License MIT
Filename extensions Common extensions
.avfp
Other extensions
extensionless
Website activevfp.codeplex.com

ActiveVFP (also known as AVFP) is a server-side scripting framework designed for Web development to produce dynamic Web pages. Similar to PHP, but using the native Visual Foxpro (VFP) language and database (or other databases like Microsoft SQL and MySQL), ActiveVFP can also be used in Model-View-Controller (MVC) 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.

Contents

ActiveVFP was originally created in 2001. The main implementation of ActiveVFP is now produced by the Foxpro Community at activevfp.codeplex.com 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. [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 automatic memory Garbage Collection (GC) and Dynamic/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

<!DOCTYPE html><html><head><metacharset="utf-8"><title>VFP code in HTML</title> ... <%*SettingslnTotPerPage=10lnpagenumbers=5lnStart=VAL(oRequest.querystring("page"))lcButton=oRequest.querystring("nav")*sqlSELE*FROMCustomerINTOCURSORtCursor*createpagenumbersSTART=0lnPageMax=0lnPageBegin=0lnRowCount=RECCOUNT()SETPROCtooProp.AppStartPath+'prg\pages' ADDITIVE   lcPages=pages(lnTotPerPage,lnpagenumbers,lnStart,lcButton,lnRowCount)%> ...  <%FORlnX=lnPageBeginTOlnPageMaxIFlnX<=lnRowCountGOTOlnX%><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><%ENDIFENDFOR%>                                ... <%=lcPages%>
* 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: <b>" + THIS.homeFolder + "</b>"  ENDPROC    PROCEDURE getAction && GET www.hostname.com/app/customers/<id>   LOCAL cCustId   cCustId = THIS.Params[1]   THIS.openData()   SELECT CUSTOMERS   LOCATE FOR custId = cCustId   IF FOUND()    LOCAL cJSON    **USE mydbf  &&test error    *quick and dirty JSON    cJSON = [{"custId":"] + RTRIM(custId) + [","custName":"] + RTRIM(custName) + [",] + ;            ["custStat":"] + RTRIM(custStat) + ["}]    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/<id>     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, [images/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 

Related Research Articles

Server-side scripting is a technique used in web development which involves employing scripts on a web server which produce a response customised for each user's (client's) request to the website. The alternative is for the web server itself to deliver a static web page. Scripts can be written in any of a number of server-side scripting languages that are available. Server-side scripting is distinguished from client-side scripting where embedded scripts, such as JavaScript, are run client-side in a web browser, but both techniques are often used together.

Vector Markup Language (VML) is an obsolete XML-based file format for two-dimensional vector graphics. It was specified in Part 4 of the Office Open XML standards ISO/IEC 29500 and ECMA-376. According to the specification, VML is a deprecated format included in Office Open XML for legacy reasons only.

Courier (typeface) Monospaced slab serif font of IBM

Courier is a monospaced slab serif typeface. The typeface was designed by Howard "Bud" Kettler (1919–1999). Initially created for IBM's typewriters, it has been adapted to use as a computer font and versions of it are installed on most desktop computers.

A lightweight markup language (LML), also termed a simple or humane markup language, is a markup language with simple, unobtrusive syntax. It is designed to be easy to write using any generic text editor and easy to read in its raw form. Lightweight markup languages are used in applications where it may be necessary to read the raw document as well as the final rendered output.

Zend Framework (ZF) is an open source, object-oriented web application framework implemented in PHP 7 and licensed under the New BSD License. The framework is basically a collection of professional PHP-based packages. The framework uses various packages by the use of Composer as part of its package dependency managers; some of them are PHPUnit for testing all packages, Travis CI for continuous Integration Services. Zend Framework provides to users a support of the Model View Controller (MVC) in combination with Front Controller solution. MVC implementation in Zend Framework has five main areas. The router and dispatcher functions to decide which controller to run based on data from URL, and controller functions in combination with the model and view to develop and create the final web page.

In computing, an attribute is a specification that defines a property of an object, element, or file. It may also refer to or set the specific value for a given instance of such. For clarity, attributes should more correctly be considered metadata. An attribute is frequently and generally a property of a property. However, in actual usage, the term attribute can and is often treated as equivalent to a property depending on the technology being discussed. An attribute of an object usually consists of a name and a value; of an element, a type or class name; of a file, a name and extension.

dwm

dwm is a dynamic, minimalist tiling window manager for the X Window System that has influenced the development of several other X window managers, including xmonad and awesome. It is externally similar to wmii, but internally much simpler. dwm is written purely in C for performance and security in addition to simplicity, and lacks any configuration interface besides editing the source code. One of the project's guidelines is that the source code is intended to never exceed 2000 SLOC, and options meant to be user-configurable are all contained in a single header file.

The Web Application Description Language (WADL) is a machine-readable XML description of HTTP-based web services. WADL models the resources provided by a service and the relationships between them. WADL is intended to simplify the reuse of web services that are based on the existing HTTP architecture of the Web. It is platform and language independent and aims to promote reuse of applications beyond the basic use in a web browser.

FlagShip

FlagShip is both an object oriented and procedural programming language, based on the xBase language dialect and conventions. FlagShip is available for and is cross-compatible to different computer platforms, such as Linux, Unix and Microsoft Windows. As a true compiler, it translates xBase source code to native 32-bit or 64-bit executables, using the same source-code and databases.

Web2py is an open-source web application framework written in the Python programming language. Web2py allows web developers to program dynamic web content using Python. Web2py is designed to help reduce tedious web development tasks, such as developing web forms from scratch, although a web developer may build a form from scratch if required.

A single-page application (SPA) is a web application or website that interacts with the user by dynamically rewriting the current web page with new data from the web server, instead of the default method of the browser loading entire new pages. The goal is faster transitions that make the website feel more like a native app.

Visual FoxPro

Visual FoxPro was a Microsoft data-centric procedural programming language that subsequently became object-oriented.

Jspx-bay

jspx-bay, commonly referred to as jspx, is a free open source pure Java web RAD framework. Jspx should not be confused with other technologies using the same name like Oracle Application Framework and XML JSP.

HTML attributes are special words used inside the opening tag to control the element's behaviour. HTML attributes are a modifier of an HTML element type. An attribute either modifies the default functionality of an element type or provides functionality to certain element types unable to function correctly without them. In HTML syntax, an attribute is added to an HTML start tag.

ColdBox Platform

ColdBox is an open-source, conventions-based, modular web application framework intended for building enterprise applications with CFML using a Hierarchical MVC approach. ColdBox uses Convention over configuration and aims for simplicity, rapid development. It makes use of Model-view-controller, Dependency injection, Unit testing, Aspect-oriented programming architectural patterns. ColdBox allows for development of stand-alone modules which can be shared across apps. ColdBox is an active and heavily documented CFML framework.

AngularJS is a JavaScript-based open-source front-end web framework mainly maintained by Google and by a community of individuals and corporations to address many of the challenges encountered in developing single-page applications. It aims to simplify both the development and the testing of such applications by providing a framework for client-side model–view–controller (MVC) and model–view–viewmodel (MVVM) architectures, along with components commonly used in rich Internet applications.

Yesod is a free and open-source web framework based on Haskell for productive development of type-safe, REST model based, high performance web applications, developed by Michael Snoyman et al.

React (JavaScript library) JavaScript library for building user interfaces

React is an open-source, front end, JavaScript library for building user interfaces or UI components. It is maintained by Facebook and a community of individual developers and companies. React can be used as a base in the development of single-page or mobile applications. However, React is only concerned with state management and rendering that state to the DOM, so creating React applications usually requires the use of additional libraries for routing, and fully-fledged form solutions. React Router and Formik are examples of such libraries respectively.

A Uniform Resource Locator (URL), colloquially termed a web address, is a reference to a web resource that specifies its location on a computer network and a mechanism for retrieving it. A URL is a specific type of Uniform Resource Identifier (URI), although many people use the two terms interchangeably. Thus http://www.example.com is a URL, while www.example.com is not.</ref> URLs occur most commonly to reference web pages (http), but are also used for file transfer (ftp), email (mailto), database access (JDBC), and many other applications.

Vue.js Open-source JavaScript framework for building user interfaces

Vue.js is an open-source model–view–viewmodel front end JavaScript framework for building user interfaces and single-page applications. It was created by Evan You, and is maintained by him and the rest of the active core team members.

References

  1. Advanced VFP Servers by Calvin Hsia, Microsoft
  2. Visual FoxPro Code Samples
  3. Windows Web Scripting Comparison