Help  |   Contact Us  |   About Us  |   News and Events
Books, conferences, and other information about... Moving to Linux Switching to OOo Building Linux Apps Using Visual FoxPro
Buy      Download      Your Account      Catalog      Support      Conferences      Resources      Fun

Hacker's Guide to Visual FoxPro 7.0
Table of Contents

Note: Be sure to download the sample CHM file for the Hacker's Guide to VFP 7.0. It's the best sample you'll ever see in your life. (Click here.)

Section 1: Wow, What a Concept!
Section 2: Ship of Tools
Section 3: Franz and Other Lists
Section 4: Visual FoxPro Reference (CHM file only)
Section 5: But Wait, There’s More!
Section 6: Back o' da Book

(Because HackFox is structured a bit differently than other books, this table of contents lists each major section plus the first paragraph or two in each section.)

Section 1: Wow, What a Concept!

Section 1 introduces the major themes of Visual FoxPro, starting with its history and covering the fundamentals of each of its major sub-languages. Think of it as the "If it's Tuesday, this must be Belgium" Tour of Visual FoxPro.

"It's Always Been That Way"

"In the beginning"—isn't that how histories normally begin? But what is the beginning of Visual FoxPro? It has bits and pieces from so many different languages and technologies that there's no one beginning. Visual FoxPro is a true hybrid.

One bit of lineage is clearer than the rest, though, and that is FoxPro's Xbase heritage. For that, there's at least a partial beginning. "In the beginning, there was the dot."


The transition from the FoxPro 2.x model of the universe to the Visual FoxPro mindset was pretty revolutionary on a lot of fronts. While we cringe to use the hackneyed and overused term, the introduction of databases in Visual FoxPro was a major paradigm shift and one that took some getting used to. The introduction of the database container, local and remote views, vast improvements in client-server connectivity, and a slew of new data types, commands, and functions was mind-boggling. We'll try to give you an overview of the data changes here, and refer you to areas where you can get more information throughout the book.

If you're coming from an Xbase background, you might think you're encountering some NewSpeak in Visual FoxPro, but it's all for a good cause. Individual DBF files used to be referred to as "databases" but now, a better term, that used by Visual FoxPro, is to call individual DBF files "tables" and the new DBC a "database container" or just "database" for short. While it's frustrating to try to change terminology you've been using for years, we've found it does lead to greater understanding of the new scheme of Visual FoxPro. Not only that, but the new names bring us in line with the rest of the relational database world.

Xbase Xplained

FoxPro's oldest heritage is its Xbase heritage. As we said in "It's Always Been That Way," Xbase has a long and varied history. This section explains the basic language concepts that derive from that history.

dBase was originally conceived primarily as an interactive language. Because of this, many of the older commands' default behaviors focus on interactive results, with optional clauses available to use the command programmatically.

SQL—The Original

SQL, which stands for Structured Query Language, is a set-based language. Unlike Xbase, which cares about individual records, SQL is interested mostly in groups of records. (The Xbase concept most similar to SQL's point of view is the FOR clause.) The name "SQL" is read by some folks as a series of letters ("ess queue ell") and by others as "sequel"—we use either one, depending on the phase of the moon, though we lean more toward the latter these days.

OOP is Not an Accident

We've heard about Object-Oriented Programming (OOP) for more than 20 years. At first, it was just theory. Then, we started hearing about this language called SmallTalk. In the last few years, OOP's been everywhere, and the claims of who has it and how it revolutionizes programming have grown louder and louder.

So what is OOP? Why is it important? And has it really changed the way we program?

Controls and KAOS

Controls are the means of interacting with users. Some, like the text box and the command button, are visual elements of the user interface; others, like the timer and the session controls, don't have a visual element, but work behind the scenes to support the user interface. Understanding the intricate ways in which the properties, events and methods are evaluated and executed is essential to grasping how Visual FoxPro works. In this section, we'll discuss what controls are and some of the features common to controls. We'll go on to look briefly at each control (you'll find more in the Reference section), and discuss where it's appropriately used. At the end of the discussion, we'll explain how the built-in characteristics of controls can be extended to create more complex and customized controls, tailored to meet your clients' needs, capable of interacting with your users in ways beyond those anticipated by Visual FoxPro's designers.

A Gala Event

What is an event? What do we need to do about it? The FoxPro family was a leader in the Xbase world in moving from a procedural application to an event-driven interface, even in DOS. With Visual FoxPro, FoxPro became fully attuned to the rich event model of the underlying Windows interface. Visual FoxPro can create far more responsive applications, and applications that are more consistent with the behaviors of other Windows programs. We'll examine the different events that are possible, under what circumstances they occur, and what code is appropriate for each of them.

"Your Server Will Be With You in a Moment"

Client-Server: definitely one of the buzzwords of the nineties. Or is that two of the buzzwords—we haven't figured out yet whether "client-server" is one word or two. We're not alone in this. A salesman for a major vendor asked to define client-server a few years ago responded, "Client-server? Why, that's whatever it is I'm selling today."

So why all the fuss about client-server? Because most organizations have their data spread out over multiple machines in at least as many formats. Client-server is advertised as the ticket to using all that data without forcing everyone to use the same applications or having to convert everything to a common format.

Of course, now that we're in the zeros (or is that the aughts?), client-server should be passé, right? Well, although it certainly gets less attention than it did when we wrote earlier editions of this book, client-server still has a lot of life left in it.

"It was Automation, You Know"

Have you ever been working in one application and really needed some capability from another? Say you were creating a report in FoxPro, but really needed Word's formatting prowess? Or maybe you needed to do calculations on a few items of data contained in a set of spreadsheets? We sure have, more times than we can count.

"Ah, What a Tangled Web We Weave"

The Internet. Unless you've been hiding in a cave for most of the past decade, you know that the Internet, and particularly the World Wide Web, has captured the lion's share of the publicity in the computer world. What is it about the Web that has attracted so much attention? What can we FoxPro developers do to capture some portion of this market? And what should we do?

This is not a primer on the technologies of the Internet—there are many fine books on that subject. Nor is it an in-depth examination of the techniques needed to assemble a robust VFP Web-based application—that's well covered in other volumes in the Essentials series, which includes the fine volume you're reading now. Check out Rick Strahl's awesome Internet Applications with Visual FoxPro 6.0, and also WebRAD: Building Database Websites with Visual FoxPro and Web Connection, by Harold Chattaway, Randy Pearson, and Whil Hentzen, both available from Hentzenwerke Publishing. Our goal is to give you a brief overview of the stuff that's involved, and then we'll dig into the stuff you can do with Visual FoxPro.

Section 2: Ship of Tools

Section 2 discusses in brief the Power Tools—the key to using Visual FoxPro effectively. You'll find our favorite tips and tricks for using the Power Tools here, too, and an introduction to integrating source control with VFP development.

When Should You Use the Power Tools?

Almost Always.

We used to say (and believe) "always" as the answer to "When should you use the Power Tools?" But some changes, both in the product and, more importantly, in the development world, mean that there are some valid reasons to write code by hand. Let's look at what the Power Tools are, and then we'll come back to the question of when not to use them.

These Are Not Your Father's Power Tools

When you walk into a hardware store, there's generally no question about what's a power tool and what's not. If it has a cord or uses batteries or gas, it's a power tool. If you make it go by the sweat of your brow, it's not.

In Visual FoxPro, the lines aren't quite as simple. There are a number of items that could be called "power tools" or not. We choose to take a fairly broad view and include in our list anything that at least partially automates a task you'd otherwise have to do by hand.

We're not going to give you step-by-step (or even general) instructions on using each of the power tools. We assume you've read the documentation or an introductory book. Instead, we concentrate here on the stuff you might have missed—shortcuts, neat tricks, and new ways of working.

As with everything else in FoxPro, there are various ways the Power Tools can be categorized. It turns out that, for the most part, the design team has done a pretty good job of pigeonholing the tools just by assigning them names, so we'll use that breakdown.

Productive Debugging

Our programs run correctly the first time, every time. Yeah, right—if you believe that one, we have a bridge in Brooklyn we'd like to sell you. We figure we spend at least as much time debugging our programs as we do writing them in the first place.

If your programs do run correctly the first time, every time, you can skip this part of the book. In fact, you should write a book and tell us how to do it. For the rest of you, we'll take a look at the kinds of errors that occur in programs, give you some ideas on how to root them out, and show how VFP can aid your efforts.

Frequently Asked Power Tool Questions

Actually, some of these are frequently asked questions and others are "we expect these to be frequently asked" questions about things. There's a mix here of stuff we're tired of answering already (we hope putting it here will cut down on the number of times we're asked) and things we think will be like that.

If you don't see your question here, check out "It's a Feature, Not a Bug"—more of this kind of stuff is there. Some other items that might be on your "how do I" list may be covered in the other chapters in Section 2 of this book. And if you still don't see your question, try one of the public support forums for VFP. (See the appendix for a list of places where kind folks answer questions and chat about FoxPro.)

A Source is a Source, Of Course, Of Course

Wait! Don't flip that page! Source code integration in Visual FoxPro is not just for team development! If you're a solo developer, or work in a group where each of you has your own project, source code control is for you, too.

The additions that came in Visual Studio 6 offered greater possibilities for tight integration of Visual FoxPro projects with the other tools supplied in the Visual Studio package. Now that Visual FoxPro 7 is no longer in Visual Studio, we see no need to panic; it still works with the other tools, especially Visual SourceSafe. However, the integration with Visual SourceSafe started with Visual FoxPro

Section 3: Franz and Other Lists

Section 3 contains a bunch of stuff that didn't fit in anywhere else in the book. Most of it can be viewed as lists of one sort or another. You'll find our hardware recommendations, our opinionated list of useless commands to avoid, optimization tips, and a collection of weird items that make you think you've found a bug.

Hardware and Software Recommendations (from a group of hardware haters) We hate hardware. Let's get that one fact out from the beginning. IRQs and memory locations, obscure settings and incompatibilities are the bane of our existence. We're FoxPro hackers, not wire weenies, and it saddens us that FoxPro requires any hardware at all—a virtual machine would be so much nicer to work on! However, this is the real world, and it's a fact.

In the years since we first wrote this section for the Hacker's Guide to Visual FoxPro 3, much has changed, and yet much remains the same. We've seen a number of flavors of Windows ship, from Windows 95 to the just-released (as of this writing) Windows XP.

"It's a Feature, Not a Bug"

It's not surprising that a language with as many different roots as FoxPro has a number of odd behaviors—things that make you say "hmmm." Some of them, of course, are bugs. But this section is dedicated to those that really aren't bugs—the ones for which there's a legitimate explanation. You'll also find a number of these items in the Reference section. Often, you'll find a design icon next to them.

Commands Never To Use

Our fellow developers amaze us. Never have a group of such clever people created so many amazing applications. And how they do it is equally stupendous, using commands or features of this remarkable language that we knew of only peripherally, or with capabilities we only suspected. However, there are a few commands whose use should be relegated to legacy code. These commands have been replaced by better, newer or safer commands; never really had a reason to exist in the first place; or they just plain break the machine.

We divide our list into two parts: commands that should never, ever be used, and commands that should only be used from the Command Window. Some commands are just useless, and we have a few favorites that we recommend you avoid altogether. But then, there are some commands that do useful things but have too many side effects to let us feel comfortable bringing them into a client's application.

Faster Than a Speeding Bullet

Speed is where it's at. No client is going to pay you to make his app run slower. Fox Software's initial claim to fame was that FoxBASE (and later, FoxBASE+ and FoxPro) ran faster than its competitors. Fox's reputation for speed was well deserved. However, the speed gain has never been automatic. You have to do things right to make your code "run like the Fox."

The Rushmore optimization technology introduced in FoxPro 2.0 is based on indexes. Rushmore examines index files to determine which records meet the conditions for a particular command. So, in order to make things fast, it's important to create the right indexes and to write code that takes advantage of those indexes. The difference between the lightning-fast code your client uses to make crucial strategic decisions and the plodding code his competition uses might differ by no more than an operator or two, so listen up!

There are also some other tricks, not related to Rushmore, that can speed up your applications considerably. This section discusses both Rushmore and non-Rushmore optimization techniques.

Section 4: Visual FoxPro Reference (e-book only)

Section 4 is the meat of the Hacker's Guide. You'll find a listing for every command, function, property, event, method and system variable. We've grouped them logically so that you can find several related topics in one place.

Section 5: But Wait, There's More!

We've sliced, we've diced, we've chopped Visual FoxPro into little pieces. But there's still more to say. A few features are so cool, they warrant their own chapters. This section goes into detail on the ActiveX technologies, the Object Browser and Component Gallery, Wizards and Builders, and IntelliSense, all of which provide opportunities for extending your use of VFP.

Active Something

In the original Hacker's Guide to Visual FoxPro 3.0, we included a chapter "OLE, OLE, Oxen Free!" that talked about the brave new world of OLE. Even at that time, OLE was not that new, but it was just catching on in the developer community. FoxPro 2.x provided support only for OLE 1.0 in its implementation, and that was pretty weak. Visual FoxPro supported OLE 2.0 but, like many "point zero" releases, there were a lot of incompatible products released under the 2.0 banner.

We've made a somewhat arbitrary decision to divide the ever-expanding subject of OLE, er, COM, into several pieces. "It was Automation, You Know" covers those technologies formerly known as OLE Automation, now simply Automation, as well as the brave new world of Automation servers created with Visual FoxPro. In this section, we take on a few of the other aspects of the technology, and look at the Registry, linking and embedding, and ActiveX controls.

Hacking the Class Browser and Component Gallery

Visual FoxPro's Class Browser and Component Gallery (or just "Browser" and "Gallery") are valuable development tools; most self-respecting VFP hacks will want to know them well.

Most of Visual FoxPro's ancillary tools, like Browser and Gallery, are actually written in Visual FoxPro. (Surprised?) Starting with VFP 6, the source code for all the VFP-coded tools is included. This is great news for VFP developers because the source for these tools provides some great (and occasionally not so great) examples. If you search carefully, you may even find an astonishing feat of software prowess: a comment in the source code.

Lack of comments aside, if you've ever wondered just how a particular wizard or service works, you can now easily and legally reverse-engineer it.

Builders and Wizards (and Bears, Oh My!)

Visual FoxPro comes with things called builders and wizards. Other Microsoft products, like Access for example, are bundled with only wizards. The difference? Mostly parlance. Builders and wizards are very similar. The difference depends on which part of the development process you're working on.

IntelliSense and Sensibility

Visual FoxPro developers have long had VB-envy, at least with regard to one particular feature: IntelliSense. Type a statement such as "Dim SomeVariable As" in Visual Basic and a list immediately pops up of all of the types a variable can be defined as—data types as well as objects. Type "SomeObject." and you're presented with a list of the properties, events and methods for that object. This feature is a great productivity booster for several reasons: You can quickly pick the item you want from the list, it avoids spelling mistakes, and it cuts down on trips to the Help file to figure out the syntax for a little-used command.

VFP 7 cures our inferiority complex by adding IntelliSense to our beloved tool, and makes up for the long wait by providing a better version of IntelliSense than Microsoft's other products have (in fact, the VFP team has been showing their cool version to the other product teams). Once you start appreciating how much more productive IntelliSense makes you, you'll wonder how you ever coded without it.

IntelliSense provides VFP developers with several very useful behaviors: automatic keyword completion, command and function syntax tips, and lists of members, values, and most recently used files.

Section 6: Back o' da Book

Resource File

In this section we list many resources we think may be of benefit to you. These include books worth reading, either for their value as a reference or as food for thought. Following that list is a list of FoxPro 2.x books to aid in your understanding of "legacy" code and techniques. Included at the end is a list of other resources worth checking into. Finally, there are a number of other good book lists out there.

What's in the Downloads?

With this edition of the Hacker's Guide, we've accepted that the Internet is for real and included fewer items in the downloads than in previous versions. Our thinking is that most of you don't want to download a ton of stuff you're never going to use in order to get the one or two items you do want. Instead, in the "Resource File" section, we've given some idea of what's out there and where to get it. The actual download is left as an exercise to the reader.