Get More Productive with VFP, Part 3 

This article may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. To maintain the flow of the article, we've left these URLs in the text, but disabled the links.

Get More Productive with VFP, Part 3

Richard Schummer

Visual FoxPro is an extremely productive development tool. This month, Rick Schummer continues his short series of articles with various tips and tricks that allow a VFP developer to be more productive using the Project Manager, IntelliSense, and the new VFP 8 Code Reference tool.

The Project Manager has been around since the early days of Visual FoxPro. Over the years we've seen improvements in the tool we use to manage all the various source code files in our applications and solutions. Somehow over time Microsoft adds a feature here or there just to save us time, often unnoticed. IntelliSense is much newer, and it revolutionized productivity in the Command Window and different code editors. In this article I'll discuss a couple of features available to developers to extend or enhance this technology within Visual FoxPro for additional productivity. Finally, I'll provide a quick introduction to one of the neatest tool additions to Visual FoxPro—the Code Reference tool—and how it can increase a developer's productivity in a very short time.

Project Manager

The Project Manager has been around for a long time, yet I'm often impressed by the features that it has to make me more productive.

Drag-n-drop

Many developers are surprised to find out that the Project Manager is a drag-n-drop client and server. This means that files can be dragged to the Project Manager from many sources, including other projects and from outside of Visual FoxPro. If you drag files from the Windows Explorer, all of the files will be added to the project.

Dragging from one project to another

Dragging files between two different projects creates a reference in the second project for that file. If there's a description for the file, this description is also added to the second project, even for files that don't store the description in the file itself. If the file is a program set as the main program of the originating project, VFP will prompt you with a question that asks if you want to make the file the main program in the second project. You don't need to be on the same page in each project. The file is naturally added to the correct category based on the file extension.

Dragging from a project to a designer

Dragging files from the project to a form or class designer can save time during development. Many project objects can be dragged to the Form or Class Designer. The dropped objects are instantiated in the designer.

Dragging a field from a database contained table, view, or free table to a form or class will instantiate the associated class for the data type. The advantage of this feature is that it creates a bound object in the class without the use of a data environment. Many developers I've instructed over the years feel they need to first drop the object on a class or form, and then set the ControlSource.

While the manual setting of the ControlSource works, it requires developers to perform an extra step. The other advantage of this technique is that it incorporates the IntelliDrop capability seen when you perform this operation from the data environment. This way, the classes specified in advance are used instead of the VFP base classes. Tables dragged to a form or classes will instantiate a grid. If you right-click and drag, you're presented with the option of the grid class (or other class you've set for the Multiple setting in the Field Mapping in Tool | Options).

If you want a specific class dropped on another container class, you can select it in the Project Manager (Class page) and drag it to the container class. This doesn't bind the object like the drag operation of a table field. This allows you to override the IntelliDrop settings that are pre-mapped. Given this functionality, one might expect that an icon dropped on a form might set the form Icon property, and that dropping a graphic would generate an image object. They don't. Other objects not mentioned in this section can't be dropped onto a form or container class.

Dragging from project to program code

In the same spirit described in the preceding section, you can drag and drop different project objects to code editors. The name of the object is displayed in the code window. For instance, if you drop a field name in the Command Window, you get the field name. Unfortunately, you don't get the table.fieldname syntax. This works for every object type in the project except the stored procedure names. The only objects that carry over the file extension are the files in the "other" category.

Dragging from Class Browser or Component Gallery to a project

I tested a couple of other ideas with this capability by dragging files from the VFP Class Browser and its close cousin, the Component Gallery. You'd expect that dragging a class from the Class Browser to the Project Manager would add the class. Unfortunately, this doesn't work. I dragged the icon in the upper left corner to the project, just like I have many times to another instance of the Class Browser. It plain does not work in VFP 6, 7, or 8. The mouse drop cursor changes to provide a visual indication that a drop can be completed, but don't get your hopes up since it doesn't work.

Even more interesting is that performing the same tests in the Component Gallery proved successful. Pick the class in the Component Gallery and drag the icon in the upper left-hand corner or the icon in the right pane and drag it to the Project Manager. If the file is a class, a dialog is presented that asks how you want to add the file to the project (see Figure 1). You have an option to add it to the existing class library or add a copy of the class to another class library. Any file that can be added to a project can be dropped from the Component Gallery. Quickly adding common files to a project from your favorite catalog is a pretty powerful technique!

Dragging from a non-VFP application to a project

Another cool capability is that files can be dragged onto the Project Manager from outside of VFP. The Project Manager is just one of many parts of VFP that were enabled for OLE Drop and Drag in VFP 6.0. So how can you leverage this feature? Pop open Windows Explorer or your favorite replacement (mine happens to be PowerDesk). If you drag and drop VFP-specific files from Explorer to the Project Manager, they're added to the appropriate category. Non-VFP files are added to the "other" category. In other words, if you drag a shortcut from the desktop, you get a shortcut (.LNK) file added to the "other" category in the Project Manager.

IntelliSense

IntelliSense was the big-ticket item in Visual FoxPro 7, and it's a huge productivity gain for developers. The biggest savings is the reduced need to hit the F1 key to bring up Help. I use Help significantly less often than in VFP 6.

ActiveX controls

Understanding the object models of ActiveX controls isn't difficult, but remembering all the properties, events, and methods can be a chore. So how can a developer get IntelliSense to do all the heavy lifting? The key is to declare a memory variable. Once it's declared, the object is live in the editor:
LOCAL loWord AS "Word.Application"

loWord = CREATEOBJECT("Word.Application")
loWord.Documents.Open(GETFILE("doc"))
loWord.ActiveDocument.Range.Bold = .T.

I've noticed in VFP 7 and VFP 8 that occasionally IntelliSense doesn't kick in when I'm editing a method that was previously edited. One workaround is to cursor through the variable declaration (in the previous example code it's the LOCAL line). It appears to give VFP the needed reference to have IntelliSense provide the list of properties and methods.

It should be noted that you don't have to declare the memory variables in the Command Window, only the editors. All ActiveX references are live in the Command Window since the CREATEOBJECT() is literally executed.

Custom expansion

Custom expansion refers to the feature of IntelliSense that allows developers to auto-expand a "word" in the same manner as Visual FoxPro commands are expanded as soon as VFP recognizes the command and the developer hits the spacebar or tab key. The custom ones are ones that Visual FoxPro developers define. This feature was available in VFP 7, but only a few custom expansions shipped with the product—MC (Modify Command), MF (Modify File), and DC (Define Class). Visual FoxPro 8 ships with a long list of new commands (see Table 1).

Table 1. A complete list of the custom expansion commands that shipped with VFP 8.

Custom command

Expanded code

DOCASE

DO CASE
CASE
OTHERWISE
ENDCASE

DOWHILE

DO WHILE
ENDDO

FOREACH

FOR EACH
ENDFOR

FOREND

FOR
ENDFOR

IFEND

IF
ENDIF

IFELSE

IF
ELSE
ENDIF

SCANEND

SCAN
ENDSCAN

TEXTEND

TEXT TO NOSHOW TEXTMERGE
ENDTEXT

TRYEND

TRY
CATCH
FINALLY
ENDTRY

WITHEND

WITH
ENDWITH

WS

(Expands out code to instantiate the selected Web Service)

List Members, Quick Info

List Members is the dropdown list of properties, events, and methods that are related to the current object hierarchy. It's displayed automatically when the object is specified, and can be manually initiated by the Ctrl+J shortcut. Quick Info is the related Help ToolTip with the parameter list (including bolding the current parameter). It's displayed automatically as well, and can be manually initiated by the Ctrl+I shortcut. In VFP 7, when the backspace was keyed in we lost both List Members and Quick Info, which meant that we needed the shortcut keys to get IntelliSense started again.

List Members doesn't stop functioning in VFP 8 when the backspace is used; it goes backwards in the list (incremental searching) as you remove characters off the property, event, or method. This saves us a ton of time by not having to remember the shortcut key to List Members.

C++ operators

If you've developed in C++ you might be aware of the incrementor/decrementor operators. These are shortcuts to expand out common code—like incrementing a numeric memory variable by typing in the memory variable with ++ added to the end of the variable. For instance, this:
lnCounter++

expands into this:

lnCounter = lnCounter + 1

Table 2 explains which operators are available as the defaults in IntelliSense. The feature is only activated with the spacebar. The Enter key doesn't expand the operators. If you find the C Operator functionality annoying, you can turn it off via the Advanced page of the IntelliSense Manager (see Figure 2).

Table 2. The operators available as a default of IntelliSense.

Operator

Feature

Example

++

Add 1 to the memory variable.

lnCounter = lnCounter + 1

--

Subtract 1 from the memory variable.

lnCounter = lnCounter - 1

+=

Add value to existing memory variable, leave value to be typed in.

lnCounter = lnCounter +

-=

Subtract value to existing memory variable, leave value to be typed in.

lnCounter = lnCounter -

*=

Multiply value to existing memory variable, leave value to be typed in.

lnCounter = lnCounter *

/=

Divide value to existing memory variable, leave value to be typed in.

lnCounter = lnCounter /

Code Reference

The new Code Reference tool is designed to do project- or folder-wide searches and replaces (optional) for text. This is a very, very nice addition to Visual FoxPro. In many ways this tool surpasses other tools that have been developed by the Fox community, and in some ways it does not.

From a productivity view, the search capability saves time looking for text in each individual form, program, menu, and so on (see Figure 3). The results of the search are saved and can be reviewed later, so you don't have to rerun searches. The existing saved searches can be refreshed (rerun) with a click of a button, which saves you time re-entering the search criteria. The results can be printed to create a checklist for you or other developers on your team. The tool allows you to export the results to any of the COPY TO formats with the capability of selecting the records output.

The result set is shown in a grid in the right pane of the user interface (see Figure 4). This pane displays the number of references found (if more than one), the filename, class/method, line number, and the source code with the reference you searched. Double-clicking on the filename will bring up the line of code with the reference in the applicable designer and code editor. This is a very fast way to get to code. You don't have to jump over to the Project Manager or even open up the project.

The results pane also has a check box available for you to select the specific file. This is used for various operations like Print and Export. Each of these features allows you to scope the output to all items or just selected items. You can also sort the results by clicking the mouse on the column headers.

The replace performs a potentially destructive operation, but it also creates backup files so you can retrieve the previous state. I still recommend making copious backups of your source code, though.

For a 1.0 tool, this one is pretty good. There are similar developer community-based tools available like Steve Dingle's Project Searcher (available at www.stevedingle.com) and Peter Diotte's GoFish (available at www.universalthread.com) that also do a great job in this regard and are available for those of you who aren't yet able to make the jump to VFP 8.

Conclusion

This month, I introduced some productivity tips using the Project Manager, some additional shortcuts for interacting with IntelliSense, and the new VFP 8 Code Reference tool. Next month we'll look at ways to improve our productivity with tips using the Visual FoxPro Debugger and Coverage Profiler.

To find out more about FoxTalk and Pinnacle Publishing, visit their website at http://www.pinpub.com/html/main.isx?sub=57

Note: This is not a Microsoft Corporation website. Microsoft is not responsible for its content.

This article is reproduced from the May 2003 issue of FoxTalk. Copyright 2003, by Pinnacle Publishing, Inc., unless otherwise noted. All rights are reserved. FoxTalk is an independently produced publication of Pinnacle Publishing, Inc. No part of this article may be used or reproduced in any fashion (except in brief quotations used in critical articles and reviews) without prior consent of Pinnacle Publishing, Inc. To contact Pinnacle Publishing, Inc., please call 1-800-493-4867 x4209.

Show: