0% found this document useful (0 votes)
35 views38 pages

Level 3 Visual Fox Pro

Uploaded by

xbhouari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views38 pages

Level 3 Visual Fox Pro

Uploaded by

xbhouari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Level 3 Visual

FoxPro 7.0:

Advanced Visual
FoxPro 7.0
Programming
Concepts
Table of Contents

Advanced Visual FoxPro 7.0 Programming Concepts


Table of Contents

INTRODUCTION .................................................................................................I-1
A Few Words About This Courseware.....................................................I-2
World-Class Courseware Taught by World-Class Instructors......I-2
What We Expect of You...............................................................I-2
What You’ll Get Out of this Training.............................................I-2
Intended Audience .......................................................................I-3
Courseware Conventions.............................................................I-3
The Practice CDs.....................................................................................I-4
Technical Requirements ..............................................................I-4
Installing the Practice Files ..........................................................I-4
What’s on the Practice CD?.........................................................I-4
Technical Requirements for the Labs ......................................................I-5
Required for All Labs ...................................................................I-5
About the Author......................................................................................I-6

WORKING WITH REMOTE DATA.....................................................................1-1


Designing Applications in Visual FoxPro that Access Remote Data ......1-2
Why Should You Access Remote Data with Visual FoxPro?......1-2
What Is Client/Server Development?..........................................1-2
Remote Data Performance Issues..............................................1-4
Deciding if Client/Server Is the Right Choice ..............................1-4
Accessing Remote Data from Visual FoxPro..............................1-5
Designing Visual FoxPro Client/Server Applications ................1-13
Offline Views .............................................................................1-14
The Visual FoxPro OLE DB Provider....................................................1-15
OLE DB vs. ODBC....................................................................1-15
Using the Visual FoxPro OLE DB Provider...............................1-16
Connecting to the Visual FoxPro Provider Using ADO .............1-16

LAB 1: WORKING WITH REMOTE DATA ......................................................1-18


Lab 1 Overview.....................................................................................1-19
Setting Up a Remote Data Source .......................................................1-20
Things to Consider....................................................................1-20
Creating Remote Views ........................................................................1-25
Things to Consider....................................................................1-25

Advanced Visual FoxPro 7.0 Programming Concepts TOC-1


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Table of Contents

VISUAL FOXPRO AND COM.............................................................................2-1


Understanding COM ...............................................................................2-2
COM Technologies .................................................................................2-3
ActiveX........................................................................................2-3
Automation..................................................................................2-3
COM+ .........................................................................................2-3
DCOM .........................................................................................2-3
MTS ............................................................................................2-3
OLE.............................................................................................2-3
COM and Visual FoxPro .........................................................................2-4
ActiveX Controls .........................................................................2-4
OLE Bound Controls ...................................................................2-6
Automation................................................................................2-11
Creating Custom Automation Servers ......................................2-24
Summary ..............................................................................................2-33

LAB 2: VISUAL FOXPRO AND COM..............................................................2-35


Lab 2 Overview.....................................................................................2-36
Controlling Another Instance of Visual FoxPro .....................................2-37
Things to Consider....................................................................2-37
Setting Up a Control for Basic OLE Drag-and-Drop .............................2-40
Things to Consider....................................................................2-40

PUBLISHING VISUAL FOXPRO DATA ON THE INTERNET............................3-1


Internet Terminology...............................................................................3-2
What Is HTML?.......................................................................................3-4
Creating an HTML Document in Visual FoxPro ..........................3-7
Saving As HTML...................................................................................3-10
The Visual FoxPro Web Publishing Wizard ..........................................3-12

LAB 3: PUBLISHING VISUAL FOXPRO DATA ON THE INTERNET.............3-21


Lab 3 Overview.....................................................................................3-22
Saving a Table as HTML ......................................................................3-23
Things to Consider....................................................................3-23
Using the Visual FoxPro Web Publishing Wizard .................................3-25
Things to Consider....................................................................3-25

VISUAL FOXPRO AND THE INTERNET...........................................................4-1


What Is HTML?.......................................................................................4-2
Creating an HTML Document in Visual FoxPro ..........................4-4

TOC-2 Advanced Visual FoxPro 7.0 Programming Concepts


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Table of Contents

The Visual FoxPro Internet Wizard.........................................................4-8


Setting Up the Internet Web Server ............................................4-8
Running the Internet Search Wizard.........................................4-10
Accessing the HTML Page with a Browser...........................................4-18
Summary ..............................................................................................4-22

LAB 4: VISUAL FOXPRO AND THE INTERNET ............................................4-23


Lab 4 Overview.....................................................................................4-24
Set Up the Web Server.........................................................................4-25
Run the WWW Search Page Wizard ....................................................4-28
Run the Visual FoxPro Server and Test the Search Page ...................4-31

INTEGRATING VISUAL FOXPRO WEB COMPONENTS .................................5-1


Introduction .............................................................................................5-2
Clients and Servers—How they Work Together .....................................5-3
HTML and Active Server Page Basics....................................................5-7
What Is HTML? ...........................................................................5-7
What Is ASP?............................................................................5-12
Integrating Visual FoxPro COM Servers and Active Server Pages ......5-14
Summary ..............................................................................................5-16

LAB 5: INTEGRATING VISUAL FOXPRO WEB COMPONENTS ..................5-17


Lab 5 Overview.....................................................................................5-18
Creating a Visual FoxPro ActiveX Server .............................................5-19
Things to Consider....................................................................5-19
Using the Visual FoxPro Server from an Active Server Page...............5-22
Things to Consider....................................................................5-22

SOURCE CODE CONTROL ..............................................................................6-1


Why Multi-Developer Projects Are Different ...........................................6-2
Understanding Source Control ...............................................................6-3
Putting Projects under Source Control ...................................................6-4
Adding Files to the Project ..........................................................6-7
Removing Files from the Project.................................................6-9
Checking Out Files....................................................................6-10
Checking In Files ......................................................................6-12
Tracking Information about the Source Control Project........................6-13
Show History.............................................................................6-13
Show Differences......................................................................6-14

Advanced Visual FoxPro 7.0 Programming Concepts TOC-3


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Table of Contents

Summary ..............................................................................................6-17

LAB 6: SOURCE CODE CONTROL ...............................................................6-18


Lab 6 Overview.....................................................................................6-19
Putting an Existing Project Under Source Control ................................6-20
Working with Project Components Under Source Control....................6-25
Things to Consider....................................................................6-25

CALLING THE WINDOWS API FROM VISUAL FOXPRO ................................7-1


What Is the API?.....................................................................................7-2
Declaring DLL Routines..........................................................................7-3
Executing DLL Routines .........................................................................7-4

ADVANCED CLASS DESIGN ............................................................................8-1


Advanced Class Design..........................................................................8-2
Designing Class Libraries ...........................................................8-2
Organizing Classes into a Hierarchy...........................................8-2
Understanding Patterns in Class Design ....................................8-6

EXTENDING THE DEVELOPMENT ENVIRONMENT.......................................9-1


What Is a Builder and Why Do I Care?...................................................9-2
Creating Visual FoxPro Builders.............................................................9-3
Creating the Form .......................................................................9-4
Project Hooks .........................................................................................9-8
The Project Object Hierarchy......................................................9-8
Projects Collection ......................................................................9-9
The Project Object ....................................................................9-10
The ProjectHook Object............................................................9-12
Project Object and the ProjectHook Object Interaction.............9-14
Files Collection..........................................................................9-15
File Object.................................................................................9-15
Servers Collection.....................................................................9-17
Server Object ............................................................................9-17
Project Object Architecture .......................................................9-17
Language Enhancements .........................................................9-18
Project Events...........................................................................9-18

TESTING AND DEBUGGING VISUAL FOXPRO APPLICATIONS .................10-1


The Debugger as a Developer’s Tool ...................................................10-2
FoxPro Frame vs. Debug Frame ..........................................................10-4
Saving Settings .........................................................................10-7

TOC-4 Advanced Visual FoxPro 7.0 Programming Concepts


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Table of Contents

The Debugger Windows .......................................................................10-8


Trace.........................................................................................10-8
Watch......................................................................................10-12
Locals......................................................................................10-13
Call Stack................................................................................10-14
Debug Output..........................................................................10-14
Event Tracking ........................................................................10-16
Setting Breakpoints.................................................................10-17
Testing Scenarios ...............................................................................10-19
Coverage and Profiling Analysis.........................................................10-20
Coverage Profiler Log File ......................................................10-20
Profile Mode............................................................................10-23

LAB 10: TESTING AND DEBUGGING VISUAL FOXPRO APPLICATIONS 10-25


Lab 10 Overview.................................................................................10-26
Stepping Through a Program .............................................................10-27
Things to Consider..................................................................10-27
Setting Breakpoints.............................................................................10-30
Things to Consider..................................................................10-30

INDEX........................................................................................................INDEX-1

Advanced Visual FoxPro 7.0 Programming Concepts TOC-5


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Table of Contents

TOC-6 Advanced Visual FoxPro 7.0 Programming Concepts


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Introduction

Introduction

Advanced Visual FoxPro 7.0 Programming Concepts Intro-1


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Introduction

A Few Words About This Courseware

World-Class Courseware Taught by


World-Class Instructors
We have worked very hard to bring you what we think are the best Visual
FoxPro training materials in the world!

What We Expect of You


This seminar doesn’t start at the beginning. To get the most out of this training,
you’ll need:

• familiarity with PCs and Windows 95, 98, NT, XP, or 2000.
• a good understanding of relational data, including the concepts of
tables and fields.
• a good understanding of application development with Visual FoxPro.
• the desire to learn.

What You’ll Get Out of this Training


Think of this training as a jump-start to creating and working with Visual
FoxPro data. After taking this class you’ll:

• Be able to work with data from Data Servers and other remote data
sources.
• Understand how to make the most of COM components.
• Access FoxPro data from other applications with the Visual
FoxPro OLE DB Provider.
• Learn how to use source code control with Visual FoxPro.
• Use the Visual FoxPro Internet tools.
• Create Internet applications using Visual FoxPro COM
components.
• Understand how to call the Windows API from Visual FoxPro.
• Understand how to design class libraries.
• Extend the Visual FoxPro Development environment.

Intro-2 Advanced Visual FoxPro 7.0 Programming Concepts


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
A Few Words About This Courseware

• Be able to test and debug Visual FoxPro applications.

Intended Audience
The training is intended for:

• Application developers who need to implement Visual FoxPro-based


solutions.

Courseware Conventions
We’ve followed several conventions to make this courseware easy to follow:

• Each chapter is numbered separately to make it easy to find your


place.
• All examples can be found on the included course CD-ROM.
• Practice file names are noted in the left-hand column.
• Most of the practice files for each chapter are on the CD-ROM under
the chapter number and name. But the Visual FoxPro Files directory
has some files that are used throughout the course. These are generally
noted in the left-hand column in the text.

Advanced Visual FoxPro 7.0 Programming Concepts Intro-3


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Introduction

The Practice CDs


Along with this book, you’ll receive a CD-ROM that contains the practice files
used in the courseware.

Technical Requirements
Many of the tools and technologies covered in this course are new and rapidly
evolving, so there are some minimum software requirements for running all
the course code:

• Windows 98, NT, XP, or 2000


• Visual FoxPro 7.0

Installing the Practice Files


Run the installation program, or simply copy the practice files from the CD to
your hard disk maintaining the folder structure. Note that the files manually
copied from the CD-ROM to your hard disk will be read-only, so you’ll have
to manually change that attribute.

What’s on the Practice CD?


The practice CD contains:

• Chapter Folders: These numbered folders contain the examples


discussed in the chapter. The chapter folder for chapters with no
examples has a single file called NoFiles.txt.
• Data Folder: This folder contains the sample data used by some of the
chapter examples.
• Lab Folders: These folders contain the files needed to conduct the
labs. Each lab folder contains a Completed folder with the expected
results of the lab. A lab folder may also contain a Start folder that
contains the starting point for the lab. Always work with a copy of the
Start folder. A lab may also contain a Data folder with the sample data
for the lab.

Intro-4 Advanced Visual FoxPro 7.0 Programming Concepts


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Technical Requirements for the Labs

Technical Requirements for the Labs


Various labs use different tools and technologies that you’ll need to install on
the machine where you’ll do the lab work.

Required for All Labs


• Windows 98, NT, XP, or 2000.
• Visual FoxPro 7.0. Some labs will work in earlier version of Visual
FoxPro.

Advanced Visual FoxPro 7.0 Programming Concepts Intro-5


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Introduction

About the Author


John M. Miller is a recognized authority on software specification, design,
and implementation. He has been designing and implementing software
applications since 1984 and has contributed to applications for numerous
public and private organizations. He speaks frequently on application design
and development issues at local, national, and international technical
conferences and has written articles for major technical publications.
Additionally, John’s expertise is sought out by application design and
development tool vendors in the evaluation and testing of their products.

John’s Fox experience dates back to 1988 when he purchased a copy of


Foxbase+ based on its promise to run his client’s Dbase III+ applications
faster. Finding this promise to be true, he has worked with every incarnation of
Fox since. Over the years he has either attended or been a featured speaker at
all the major Fox developer conferences, written numerous articles for Fox
technical publications, and was an author of one of the original Pros’ Talk Fox
books. John has been teaching Fox for AppDev since 1992 and has consulted
with numerous clients on their FoxPro projects. However John’s most
significant contribution to the FoxPro community is a program he wrote in
1992 for FoxPro DOS, which can be downloaded from
ftp://pdata.com/vfoxpro/jmm.prg.

For current information about John, see his Web site


http://www.pdata.com/jMM.6

Intro-6 Advanced Visual FoxPro 7.0 Programming Concepts


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Integrating Visual FoxPro Web Components

Integrating Visual
FoxPro Web
Components
Objectives
• Understand how clients and servers interact in a distributed
application.
• Investigate the basics of creating a Web application with Visual
InterDev and Active Server Pages.
• Discover how to create Visual FoxPro COM servers.
• Learn how to call Visual FoxPro COM servers from Active Server
Pages.

Advanced Visual FoxPro 7.0 Programming Concepts 5-1


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Integrating Visual FoxPro Web Components

Introduction
No matter where you turn, the Internet is there. Where only a few years ago
doing serious work on the Internet was a novelty, it is now commonplace.
Purchasing goods and services of all kinds on the Internet has become the rule,
not the exception.

The key of course is that application development tools have evolved to the
state of being able to create applications that provide a rich user experience on
the Web. Where before, Internet-based applications were unreliable and had
non-intuitive interfaces, today’s Internet-based applications have user
interfaces that are feature-rich and are very intuitive to navigate. Of course,
tools by themselves cannot get the job done alone. Never before has server
power been more affordable. Couple server power with high bandwidth
services today such as DSL, Cable, and T1/T3 and a suitable platform now
exists for mainstream Internet-based applications.

Visual FoxPro COM Servers coupled with Active Server Pages created with
Visual InterDev make an excellent environment for creating Internet-based
applications. Combining the Visual FoxPro language and Visual InterDev’s
ability to produce content that can be delivered to the Internet, makes creating
Internet-based applications easier than ever.

5-2 Advanced Visual FoxPro 7.0 Programming Concepts


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Clients and Servers—How they Work Together

Clients and Servers—How they Work


Together
Internet computing is really no different than traditional network computing
over a LAN. Both utilize clients and servers. The difference that does exist
relates to where the application elements are located. In traditional LAN
applications, both the client and server exist on the same network with a
persistent connection between the two elements. In the case of Internet-based
applications, clients and servers are not only physically separated; a persistent
connection does not exist.

In the most basic terms, clients make requests and servers process the requests
of clients. In LAN scenarios, clients usually perform a portion of the
processing, whether it is business rule enforcement and/or data processing.
Regarding the latter, data processing, has been a strong point of Visual FoxPro.
Today, Visual FoxPro is still the best performing tool when it comes to local
data processing. In addition, Visual FoxPro sports powerful tools for quickly
building rich client user interfaces.

Continuing with the LAN-based scenario, it is important to discuss the role of


the server. In most LAN-based Visual FoxPro, the bulk of the application logic
is contained in a single EXE file, which may reside on either the client
workstation or the server machine. Figure 1 illustrates a typical 2-tier LAN-
based architecture.

Advanced Visual FoxPro 7.0 Programming Concepts 5-3


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Integrating Visual FoxPro Web Components

Figure 1. In a LAN-based scenario, very often, the core application logic exists in
a single EXE file, which may reside on either the client workstation or the server.
In this scenario, the data resides on the server.

Up to this point, the role of clients and servers has been relegated to hardware.
Client and server components can also be in the form of software. To make
things even more interesting, software components can take on both roles of
client and server. Consider a 3-tier scenario in which the user interface is on
the client, and the business rules are contained on the server. From a hardware
perspective, the architecture is the same as in Figure 1. From a software
perspective however, things are a bit more complex. The user interface is
squarely in the client domain. The data store is completely in the server
domain. The middle-tier component for business rules can be both a client and
a server. From the perspective of the user interface, the business rule
component is a server because the user interface requests its services. From the
perspective of the data store, the component is a client because it requests data.
Regardless of whether the business rule components are on the same physical
machine or spread across different machines, this distinction will still hold
true.

5-4 Advanced Visual FoxPro 7.0 Programming Concepts


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Clients and Servers—How they Work Together

From a logical standpoint, the difference between N-tier LAN-based


applications and Internet-based applications is not that different. The two basic
elements exist; client and server. On a physical level, the elements are very
different. In the case of an Internet-based application, a persistent connection
between client and server does not exist. The client is usually in the form of a
Web browser. The server in this case is actually made up of multiple
components. In this context, the discussion focuses on a scenario consisting of
Windows NT and IIS (Internet Information Server). Windows NT relies on a
multitude of services to carry out tasks. In the case of responding to requests
received via the Internet, Windows NT utilizes IIS. It is up to the Web server,
IIS in this case, to make sure any other components are called in order to fulfill
the requests of the various Web browser clients. Figure 2 illustrates an
Internet-based architecture.

Advanced Visual FoxPro 7.0 Programming Concepts 5-5


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Integrating Visual FoxPro Web Components

Figure 2. A physical connection does not exist between the client and server in an
Internet-based application.

As with a LAN-based scenario, the business rule components and data store
can reside on the same physical machine as the Web server. Alternatively, the
business rule components and data store can be spread across multiple
machines if necessary.

5-6 Advanced Visual FoxPro 7.0 Programming Concepts


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
HTML and Active Server Page Basics

HTML and Active Server Page Basics


Anytime a new technology is discussed, at least two things are certain. First,
the new jargon must be learned. Second, in the case of application
development tools, new syntax must be learned as well. The tools used in
creating Internet-based applications are no different. The syntax in question
here falls into two basic categories: client and server dependent. HTML
(Hypertext Markup Language), while it is rendered to a client Web browser
from a server, depends on characteristics of the client with regard to how it
will appear to the user. Active Server Pages (ASP), also known as server-side
scripting, does not rely on the client to carry out its work. It is important to
note that it is not an either/or situation with HTML and ASP. Although
different, both are used in the delivery of Internet-based applications. The
following two sections will help to clarify the distinction between the two.

What Is HTML?

See HTML is a text markup language (as opposed to a programming language such
HTMLSample.htm as Visual FoxPro, Visual Basic, or Visual C++). While the implementation of
programming languages such as Visual FoxPro is to write code to accomplish
a task, the purpose of HTML is to deliver formatted content to the client.
Unlike other languages, HTML does not have commands. Rather, it is made up
of tags that dictate the appearance of Web browser content. The following code
shows the source code of a sample HTML document:

Advanced Visual FoxPro 7.0 Programming Concepts 5-7


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Integrating Visual FoxPro Web Components

<HTML>
<HEAD>
<TITLE>A Sample HTML Document</TITLE>
</HEAD>
<BODY>
<H1>Heading 1</H1>
<HR>
<H2>Heading 2</H2>
<H3>Heading 3</H3>
<H4>Heading 4</H4>
<H5>Heading 5</H5>
Normal text...
<H1>A bulleted List</H1>
<UL>
<LI>Line Item One</LI>
<LI>Line Item Two</LI>
</UL>
<H1>A table</H1>
<TABLE Border>
<TR><TH>Table Heading</TR>
<TR><TD>Row one</TD></TR>
<TR><TD>Row two</TD></TR>
</TABLE>
</BODY>
</HTML>

Figure 3 illustrates how the HTML appears in Internet Explorer.

5-8 Advanced Visual FoxPro 7.0 Programming Concepts


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
HTML and Active Server Page Basics

Figure 3. The sample HTML document displayed using the Internet Explorer Web
browser.

Advanced Visual FoxPro 7.0 Programming Concepts 5-9


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Integrating Visual FoxPro Web Components

There are many tags in the latest HTML specification, 4.0. A great online
reference of what comprises HTML can be found at the World Wide Web
Consortium Web site: http://www.w3.org/MarkUp/Guide/. Table 1 outlines the
most common HTML Tags.

Tag Definition

<HTML> Specifies the beginning of an HTML document.


<HEAD> Specifies the beginning of the heading section of an HTML document.
<TITLE> Specifies the title of the HTML document. The title appears in the title bar of the Web
browser window.
<UL> Specifies the beginning of a bulleted list.
<LI> Specifies an item in a bulleted list.
<H1> Specifies the beginning of a heading line. Six different heading styles are defined in the
HTML specification.
<B> Specifies that text should appear in boldface.
<HR> Specifies a horizontal rule line.
<P> Specifies the beginning of a new paragraph.
<TABLE> Specifies the beginning of a table definition.
<TR> Specifies a new table row.
<TH> Specifies a table heading.
<TD> Specifies a table cell (a column within a single row).
<FONT> Specifies font characteristics for text.
Table 1. Common HTML tags.

Many HTML tags actually come in pairs. The first is the beginning tag. The
beginning tag specifies where the specific format style should begin. These
tags are outlined in Table 1. The second component is the ending tag. The
ending tag specifies where the specific format style should end. Ending tags
look like beginning tags with the exception of being preceded by the /
character. For example, the ending tag for <H1> is </H1>.

Most tags also have attributes. Consider the <TABLE> tag. If you wish to
have a border appear for the table, the Border Attribute would be used as
follows: <TABLE Border>. The <FONT> tag has many attributes. For
example, to display text using the Arial font with a 14-point size, the HTML
code would appear as follows:

<FONT FACE="Arial" SIZE="4">Test Text</FONT>

5-10 Advanced Visual FoxPro 7.0 Programming Concepts


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
HTML and Active Server Page Basics

If you had to memorize all of the tags and their associated attributes, authoring
HTML pages would be an extremely difficult task. Fortunately, there are many
tools on the market today that make page authoring much simpler. Two
popular tools are Microsoft FrontPage and Allaire’s HomeSite. In a visual
authoring environment, you get to concentrate on the content, not the specific
tags that are in use. FrontPage allows you to author the pages as if you were
working with a word processor such as Microsoft Word. At any time however,
you can switch to view the raw HTML code and work with that syntax
interactively. Figure 4 and Figure 5 show Microsoft FrontPage.

Figure 4. The sample HTML document hosted in Microsoft FrontPage.

Advanced Visual FoxPro 7.0 Programming Concepts 5-11


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Integrating Visual FoxPro Web Components

Figure 5. The HTML view of the sample document in FrontPage.

What Is ASP?
To review, HTML is about content. How HTML appears is dependent on both
what the server produces and the specific browser being used. If you stay
within the general HTML specification, your HTML documents should have a
consistent appearance across different browsers. All of the code to this point
has dealt with tags. ASP on the other hand, deals with combining HTML and
code that executes on the server. You have two basic choices when it comes to
which language to use. The two primary scripting languages today are
VBScript and JavaScript (JScript). With server-side scripting schemes like
ASP, all of the code executes on the server, not the client. This is why server-
side processing is basically browser independent. As long as you remain
within the HTML specification with regard to what is sent to the client, you
can do just about anything you want on the server.

ASP is Microsoft’s implementation of server-side scripting. Where HTML is


static, ASP content can be dynamic, since it executes whenever a page from
the server is requested. ASP also allows pages to interact with COM
Components such as ADO, as well as COM Components you author in Visual

5-12 Advanced Visual FoxPro 7.0 Programming Concepts


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
HTML and Active Server Page Basics

FoxPro. In many ways, ASP can be viewed as the glue that ties HTML content
and business logic housed in COM Components together.

You may recall that the point was made earlier that HTML does not have
commands. As such, it cannot make decisions such as looping or branching.
ASP allows you to mix the power of conditional branching and looping with
HTML to produce intelligent, self-configuring documents. It is not unlike what
you can do to produce text documents from a Visual FoxPro program using
Visual FoxPro’s text merge features.

Advanced Visual FoxPro 7.0 Programming Concepts 5-13


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Integrating Visual FoxPro Web Components

Integrating Visual FoxPro COM


Servers and Active Server Pages
Scripting languages by nature are thin. Writing logic to drive validation
processes can be a lengthy process. In addition, because you embed scripts
directly on a page, the issue of reusability comes into play. The good news is
that you don’t have to give up your rich language in Visual FoxPro when you
deploy applications to the Internet. Beginning with Visual FoxPro 5.0, the
ability exists to encapsulate Visual FoxPro code in COM DLLs. Active Server
Pages and COM DLLs integrate very easily.

The following ASP page calls the Employee class created in the COM chapter
and displays the result of the GetSalary method:

<%@ language=vbscript%>
<html>
<head>
<title>Test</title>
</head>
<body>
<p>Today's date is
<%=Now()%>
.</p>
<p>Salary is
<%=GetSal()%>
.</p>
</body>
</html>
<%
Function GetSal
Dim oEmp
Set oEmp = CreateObject("myServer.employee")
GetSal = oEmp.GetSalary()
'oEmp = Nothing
end Function
%>

5-14 Advanced Visual FoxPro 7.0 Programming Concepts


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Integrating Visual FoxPro COM Servers and Active Server Pages

Because Visual FoxPro is used to enforce business rules, complex validations


can be written and deployed very easily.

Advanced Visual FoxPro 7.0 Programming Concepts 5-15


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Integrating Visual FoxPro Web Components

Summary
• HTML is used for the development of content that is returned to the
client browser.
• Active Server Pages allow you to combine programming logic with
HTML to create dynamic content.
• An ASP script is a server-side script, written using VBScript or
JScript, and executes on the server prior to the page being returned to
the client. Server-side scripts act as the glue that ties HTML and COM
Components together and allows conditional generation of dynamic
HTML.
• Visual FoxPro COM Components consist of Visual FoxPro
Application code that is encapsulated in a COM DLL and callable as a
server from an Active Server Page.
• You can use Visual InterDev to tie together HTML pages, Active
Server Pages, and Visual FoxPro COM Components into a Web
application.

5-16 Advanced Visual FoxPro 7.0 Programming Concepts


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Summary

Lab 5:
Integrating Visual
FoxPro Web
Components
TIP: Because this lab includes a great deal of typed code, we’ve tried to make it
simpler for you. You’ll find all the code in Integrating VFP Web
Components.txt, in the same directory as the sample project. To avoid typing
the code, you can cut/paste it from the text file instead.

Advanced Visual FoxPro 7.0 Programming Concepts 5-17


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Lab 5:
Integrating Visual FoxPro Web Components

Lab 5 Overview
In this lab you’ll learn to create a small Visual FoxPro server and then create
an ASP to make test calls to it.

To complete this lab, you’ll need to work through two exercises:

• Creating a Visual FoxPro ActiveX Server


• Using the Visual FoxPro Server from an Active Server Page
Each exercise includes an “Objective” section that describes the purpose of the
exercise. You are encouraged to try to complete the exercise from the
information given in the Objective section. If you require more information to
complete the exercise, the Objective section is followed by detailed step-by-
step instructions.

5-18 Advanced Visual FoxPro 7.0 Programming Concepts


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Creating a Visual FoxPro ActiveX Server

Creating a Visual FoxPro ActiveX


Server

Objective
In this exercise, you’ll create a simple COM server that exposes the following
methods in order to provide functions that don’t have direct equivalents in
Visual Basic for Applications (VBA), the most commonly used server-side
scripting language in ASPs. You’ll then be able to gain this useful
functionality in your ASP code.

StrTran( ): A wrapper for Visual FoxPro’s native STRTRAN( ) function.

DTOC( ): A wrapper for Visual FoxPro’s native DTOC( ) function.

Things to Consider
• How to create a Visual FoxPro server DLL.
• How to test a Visual FoxPro server DLL.

Step-by-Step Instructions

NOTE The following instructions create the server entirely in code. You
may create the equivalent methods in the Class Designer if you
prefer. Don’t forget to mark the class “OLE Public.”

1. Start Visual FoxPro, create a new project, and call it TestServer.

2. Click the Code tab, make sure Programs is highlighted, and click New.

3. In the resulting code-editing window, enter the following code, or copy


and paste it from Integrating VFP Web Components.txt.

Advanced Visual FoxPro 7.0 Programming Concepts 5-19


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Lab 5:
Integrating Visual FoxPro Web Components
DEFINE CLASS TestServer AS Custom OLEPUBLIC
See
TestServerStart.prg
PROTECTED FUNCTION Init()
SET CENTURY ON
SET HOURS TO 24
SET EXACT ON
SET TALK OFF
ENDFUNC

FUNCTION StrTran(cText,cSearch,cReplace)

IF PCOUNT() = 2
RETURN STRTRAN(cText,cSearch)
ELSE
RETURN STRTRAN(cText,cSearch,cReplace)
ENDIF

ENDFUNC

FUNCTION DTOC(uDate,n)

IF PCOUNT() = 1
RETURN DTOC(uDate)
ELSE
RETURN DTOC(uDate,n)
ENDIF

ENDFUNC

ENDDEFINE

4. Save the program as TestServerStart.prg and then click the Build button
in the Project Manager.

5. Build an in-process DLL. Figure 6 shows the appearance of the build


screen.

5-20 Advanced Visual FoxPro 7.0 Programming Concepts


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Creating a Visual FoxPro ActiveX Server

Figure 6. The Build Options dialog box.

6. In the Command Window, create an instance of the in-process server:

oTest = CREATEOBJECT('TestServer.TestServer')

TIP: The DLL is automatically registered on the machine it’s compiled on. The
server name is the name of the project plus the name of the class within that
project (DLL) you wish to create an instance of.

7. Test the server from the Command Window with statements like these:

* Returns the current date in YYYYMMDD format


? oTest.DTOC(DATE(),1)
* Returns "I Like Fries"
? oTest.StrTran('I Like Burgers',' Burgers',' Fries')

8. When finished, destroy the instance of the TestServer class by issuing


RELEASE oTest from the Command Window.

Advanced Visual FoxPro 7.0 Programming Concepts 5-21


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Lab 5:
Integrating Visual FoxPro Web Components

Using the Visual FoxPro Server from


an Active Server Page

Objective
In this exercise, you’ll create a very basic Active Server Page that calls the
server and displays the results.

Things to Consider
• Basic ASP coding techniques.

Step-by-Step Instructions
1. This lab assumes that you don’t have any Web page design tools or a
server to test your ASP page. You can get a feel for creating the code even
if you can’t test it.

2. Use Visual FoxPro’s MODIFY FILE command or NotePad to create the


following ASP file:

See Sample.asp
<%@ language=vbscript%>

<html>

<head>

<title>Test</title>

</head>

<p>Today's date is <%=Now() %>.</p>

</body>

</html>

5-22 Advanced Visual FoxPro 7.0 Programming Concepts


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Using the Visual FoxPro Server from an Active Server Page

3. Here is the HTML that might be returned to the client browser based on
the previous code:

<html>

<head>

<title>Test</title>

</head>

<p>Today's date is 4/27/2002 12:07:21 PM.</p>

</body>

</html>

4. If you have a Web server available, and time to install a copy of your
Visual FoxPro “TestServer,” you can test your ASP live. Figure 7 shows
how the finished page would look.

Figure 7. The page as the client would see it in their browser.

Advanced Visual FoxPro 7.0 Programming Concepts 5-23


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.
Lab 5:
Integrating Visual FoxPro Web Components

5-24 Advanced Visual FoxPro 7.0 Programming Concepts


Copyright © by Application Developers Training Company and AppDev Products Company, LLC
All rights reserved. Reproduction is strictly prohibited.
Licensed to ITCourseware, LLC. Reprinted with permission.

You might also like