VisualFoxPro

一,概述

Visual FoxPro原名FoxBase,是1984年美国Fox Software公司推出的数据库产品,在DOS上运行,与xBase系列兼容。FoxPro原来是FoxBase的加强版,最高版本曾出过2.6。1992年,Fox Software被微软收购,加以发展,使其可以在Windows上运行 16bit 版本为 FoxPro for Windows Ver 2.6,中文版为 FoxPro for Windows 2.5b,之后 32bit 版本并且更名为 Visual FoxPro。

Visual FoxPro 3.0一推出,就受到广大用户的欢迎。因为xBase类的语言,如dBase、Clipper等,当时还无法在Windows上运行,于是 Visual FoxPro 成为市场上的霸主。

微软后来又顺势将Visual FoxPro包入Visual Studio中。到7.0的时候,为了因应.NET的发展策略,又将 Visual FoxPro移出Visual Studio,并将Visual Studio更名为Visual Studio.Net。

目前最新的版本是 9.0。

日前,在微软官方网站释出了一份公告A Message to the Community,说明未来将不会再推出 VFP 10,并且持续 VFP 9 的支援到 2015 年,之后只会在 2007 年夏季推出 SP2。2006年进行的 Sedna 专案则是增强VFP对SQL Server 2005与 Vista的支援,其他的一些专案则已经开源到CodePlex。

VFP 3 - Taz   VFP 5 - RoadRunner   VFP 6 - Tahoe   VFP 7 - Sedona   VFP 8 - Toledo   VFP 9 - Europa   VFP Next - Sedna

二,样例

Hello World example:

MESSAGEBOX("Hello World")

Object

loForm = CREATEOBJECT("HiForm")   loForm.Show(1)       DEFINE CLASS HiForm AS Form AutoCenter = .T. Caption = "Hello, World"     ADD OBJECT lblHi as Label WITH  Caption = "Hello, World!"   ENDDEFINE       loMine = CREATEOBJECT("MyClass")   ? loMine.cProp1&& This will work.   ? loMine.cProp2&& Program Error: Property CPROP2 is not found.       ? loMine.MyMethod1() && This will work.   ? loMine.MyMethod2() && Program Error: Property MYMETHOD2 is not found.       DEFINE CLASS MyClass AS Custom   cProp1 = "My Property"&& This is a publicproperty  HIDDENcProp2&& This is a private (hidden)property      PROCEDURE Init()&& Classconstructor  This.cProp2 = "This is a hidden property." ENDPROC     PROCEDURE MyMethod1()&& This is a publicmethod  RETURN This.MyMethod2() ENDPROC     HIDDEN PROCEDURE MyMethod2() && This is a private (hidden)method  RETURN This.cProp2 ENDPROC   ENDDEFINE

Data handling

* Create a table   CREATE TABLE randData (iData I)     * Populate with random data using xBase and SQL DML commands   FOR i = 1 TO 50   APPEND BLANK   REPLACE iData WITH (RAND() * 100)       INSERT INTO randData (iData) VALUES (RAND() * 100)   ENDFOR       * Place a structural index on the data   INDEX ON iData TAG iData   CLOSE ALL       * Display sorted data using xBase-style commands   USE randData   SET ORDER TO iData   GO TOP   LIST NEXT 10 && First 10 (end-of-line comment)   SKIP 81   LIST NEXT 10 && Last 10   CLOSE ALL       * Browse sorted data using SQL DML commands   SELECT * ;   FROM randData ;   ORDER BY iData DESCENDI * Populate with random data using xBase and SQL DML commands   FOR i = 1 TO 50 APPEND BLANK REPLACE iData WITH (RAND() * 100)     INSERT INTO randData (iData) VALUES (RAND() * 100)   ENDFOR     * Place a structural index on the data   INDEX ON iData TAG iData   CLOSE ALL       * Display sorted data using xBase-style commands   USE randData   SET ORDER TO iData   GO TOP   LIST NEXT 10 && First 10 (end-of-line comment)   SKIP 81   LIST NEXT 10 && Last 10   CLOSE ALL       * Browse sorted data using SQL DML commands   SELECT * ;   FROM randData ;   ORDER BY iData DESCENDI * Place a structural index on the data   INDEX ON iData TAG iData   CLOSE ALL     * Display sorted data using xBase-style commands   USE randData   SET ORDER TO iData   GO TOP   LIST NEXT 10 && First 10 (end-of-line comment)   SKIP 81   LIST NEXT 10 && Last 10   CLOSE ALL       * Browse sorted data using SQL DML commands   SELECT * ;   FROM randData ;   ORDER BY iData DESCENDI * Display sorted data using xBase-style commands   USE randData   SET ORDER TO iData   GO TOP   LIST NEXT 10 && First 10 (end-of-line comment)   SKIP 81   LIST NEXT 10 && Last 10   CLOSE ALL     * Browse sorted data using SQL DML commands   SELECT * ;   FROM randData ;   ORDER BY iData DESCENDI * Browse sorted data using SQL DML commands   SELECT *  FROM randData  ORDER BY iData DESCENDING

ODBC Access using SQL Passthrough

* Connect to an ODBC data source   LOCAL nHnd   nHnd = SQLCONNECT ("ODBCDSN", "user", "pwd")     * Execute a SQL ccommand   LOCAL nResult   nResult = SQLEXEC (nHnd, "USE master")   IF nResult < 0   MESSAGEBOX ("MASTER database does not exist!")   RETURN   ENDIF       * Retrieve data from the remote server and stores it in   * a local data cursor   nResult = SQLEXEC (nHnd, "SELECT * FROM authors", "QAUTHORS")       * Update a record in a remote table using parameters   LOCAL cAuthorID, cAuthorName   cAuthorID = "1001"   cAuthorName = "New name"   nResult = SQLEXEC (nHnd,"UPDATE authors SET auth_name = ?cAuthorName WHERE auth_id = ?cAuthorID")       * Close the connection   SQLDISCONNECT(nHn * Execute a SQL ccommand   LOCAL nResult   nResult = SQLEXEC (nHnd, "USE master")   IF nResult < 0 MESSAGEBOX ("MASTER database does not exist!") RETURN   ENDIF     * Retrieve data from the remote server and stores it in   * a local data cursor   nResult = SQLEXEC (nHnd, "SELECT * FROM authors", "QAUTHORS")       * Update a record in a remote table using parameters   LOCAL cAuthorID, cAuthorName   cAuthorID = "1001"   cAuthorName = "New name"   nResult = SQLEXEC (nHnd,"UPDATE authors SET auth_name = ?cAuthorName WHERE auth_id = ?cAuthorID")       * Close the connection   SQLDISCONNECT(nHn * Retrieve data from the remote server and stores it in * a local data cursor   nResult = SQLEXEC (nHnd, "SELECT * FROM authors", "QAUTHORS")       * Update a record in a remote table using parameters   LOCAL cAuthorID, cAuthorName   cAuthorID = "1001"   cAuthorName = "New name"   nResult = SQLEXEC (nHnd,"UPDATE authors SET auth_name = ?cAuthorName WHERE auth_id = ?cAuthorID")       * Close the connection   SQLDISCONNECT(nHn * a local data cursor   nResult = SQLEXEC (nHnd, "SELECT * FROM authors", "QAUTHORS")     * Update a record in a remote table using parameters   LOCAL cAuthorID, cAuthorName   cAuthorID = "1001"   cAuthorName = "New name"   nResult = SQLEXEC (nHnd,"UPDATE authors SET auth_name = ?cAuthorName WHERE auth_id = ?cAuthorID")       * Close the connection   SQLDISCONNECT(nHn * Update a record in a remote table using parameters   LOCAL cAuthorID, cAuthorName   cAuthorID = "1001"   cAuthorName = "New name"   nResult = SQLEXEC (nHnd,"UPDATE authors SET auth_name = ?cAuthorName WHERE auth_id = ?cAuthorID")     * Close the connection   SQLDISCONNECT(nHn * Close the connection   SQLDISCONNECT(nHnd)

参见

Microsoft Visual Foxpro 6.0中文版教程--初级教程.rar 1366k

VFP60Help.chm 1729k

VFP全系列教程.chm 2218k

VFP教程.rar 4709k

《Visual FoxPro 6.0程序設計》電子教案.rar 1915k

Thoughts about Visual FoxPro 10

VFP爱好者站 我的帮助 www.myf1.net 使用Visual FoxPro建立自己的框架

梅子Visual Foxpro论坛 VFP全系列教程

VFP与Flash之间的相互控制--数据交互

FoxPro Wiki

VFP永不过时(2)