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.

Hidden Secrets of the VFP IDE, Part 1

Cathy Pountney

FoxPro has always had several different ways to do the same thing. How many times have you looked over the shoulder of another developer and said, "Hey! How did you do that?" In this series of articles, Cathy Pountney will uncover many ways to work within the IDE, especially those that aren't so obvious or aren't documented. You'll learn several different ways to improve your productivity. Even experienced developers are bound to learn something new.

In Part 1 of this two-part series, I'll uncover many hidden secrets in several areas of Visual FoxPro. I'll discuss various designers, a few controls, the Property Sheet, the Document View, the Find dialog, IntelliSense, and several tools and utilities included with Visual FoxPro. In Part 2 of this series I'll reveal secrets of the Command window and several commands, and wrap up with a potpourri of hidden secrets.

Report Designer

Of course you knew I was going to start with my favorite designer, the Report Designer!

Navigate between objects

In VFP 8, you can navigate between controls on a report simply by using Tab to go to the next control and Shift+Tab to go to the previous control. In versions prior to VFP 8, you have to use Ctrl+Tab to first get into tab mode, and then you can tab through objects with Tab and Ctrl+Tab.

Edit an existing label

To edit the text of an existing label object on a report, simply select the object and then press Ctrl+E. This puts you into an edit mode so that you can change the text on the label.

Forms Designer

VFP has some tricks for working with containers.

Drilling into containers

Working with container objects, such as a pageframe, can be difficult sometimes. However, you can quickly edit an object inside of a container by using Ctrl+Click over the object. This passes through the container and lets you edit the control inside of the container.

When you have containers nested within containers, you can use Ctrl+Shift+Click to drill to the deepest level. For example, if you have an optiongroup on a page of a pageframe, you can position your cursor over one of the optionbuttons, press Ctrl+Shift+Click, and VFP drills through the pageframe, and through the page, and through the optiongroup, and right into the optionbutton.

Listbox and combobox controls

The "\" character has special meanings when used in listboxes and comboboxes—see Table 1 for details.

Table 1. Using the "\" character in listboxes and comboboxes.

Char

Description

\

If the "\" is used as the first character, the entire item is disabled.

\\

Because a single backslash has special meanings, if you truly want a "\" in the item, you must use two backslashes together.

\]

Because a single backslash at the beginning of an item means that it should be disabled, if you truly have an item that starts with a backslash, you have to use "\]" to indicate that this should not be disabled.

\-

A backslash followed by a dash means that you want a horizontal line drawn for this item.

Grid controls

Grids have always been somewhat difficult to work with, especially for new developers, because some things just aren't intuitive.

Adding controls

As columns are added to a grid, you automatically get two controls—a header control called Header1 and a textbox called Text1. However, in many cases you need something other than a textbox. Unfortunately, it's not easy to figure out how to add and delete controls inside of columns.

The first thing you have to do is drill into the grid. Place your mouse over one of the rows of the column you want to change and press Ctrl+Click. Be sure you're on one of the data rows of the grid and not the header row. You now have the column active and you can use the Form Control toolbar to drag and drop the object you want into the column.

When you drop the object on the column, it doesn't look like anything happened. However, if you look at the Property Sheet and drill into the column, you'll see that the original Text1 textbox is there as well as the object you just added. The CurrentControl property of the column is still set to Text1, which is why you don't see your object.

If you were to change the CurrentControl property of the column to the name of the object you just added, the grid would show your object. However, if you don't really need the original Text1 textbox, you might as well get rid of it and not worry about having to set the CurrentControl property.

Deleting controls

If you thought adding a control wasn't very intuitive, I'm sure you're going to roll your eyes when you learn how to delete an unwanted control. It's about as unintuitive as it can get. First, select the control you want to delete in the Property Sheet. Next, use your mouse to click on a data row in the grid and then press the Delete key to delete the control. Even though nothing may have appeared visually in the grid, if you look at the Property Sheet, the object will be gone now.

Navigation

Grids present another interesting problem to end users. Users are trained that Tab takes them to the next control. However, when inside a grid, Tab moves between columns in the grid. So how does a user get out of the grid? The answer is to use Ctrl+Tab to navigate to the control after the grid or use Ctrl+Shift+Tab to navigate to the control before the grid.

The Property Sheet

There are several different keyboard shortcuts for invoking, navigating, and setting values in the Property Sheet (see Table 2).

Table 2. Keyboard shortcuts for invoking, navigating, and setting values in the Property Sheet.

Keyboard shortcut

Description

Alt+DoubleClick

Pressing this combination from the Forms Designer activates the Property Sheet, even if it isn't displayed.

RightClick (Property Sheet)

Pressing RightClick on an unused area of the Property Sheet brings up a menu with additional options. The Non-Default PEMs Only option toggles between displaying all PEMs and only those with non-default values.

RightClick (property)

Pressing RightClick on a property with a character value brings up a menu with the Zoom option. Select Zoom to display a larger edit window for the character value of the property.

Shift+UpArrow/DownArrow

Pressing this combination when on a property with multiple values navigates through all of the valid values for that property.

.

When on a logical property, a period toggles between .t. and .f.

Ctrl+PageUp/PageDown

This combination goes to the next or previous object in the Property Sheet.

Ctrl+Home/End

This combination goes to the first or last object in the Property Sheet.

Ctrl+Alt+<letter>

Pressing Ctrl+Alt plus any letter jumps to the first PEM that starts with that letter.

Editor

Many of us spend much of our day inside the VFP code editor. After all, that's what we do—write code! The following tips expose some of the hidden secrets inside the editor.

Document View

The Document View is a great tool that lets you navigate through the various procedures and functions. But did you know that you don't have to activate the Document View window to take advantage of this feature? As long as the Document View window is open, you can press Ctrl+PageUp and Ctrl+PageDown to navigate through the items in the list. You don't have to jump to the Document View window, do your navigation, and then jump back to the program.

Case

If you're a stickler about uppercase and lowercase, you can use Ctrl+U to convert the highlighted text to lowercase and Ctrl+Shift+U to convert to uppercase.

Bookmarks

Bookmarks are great when you're working with a lot of code. You can read through some code and see a reference to another method or function. Of course, you need to go look at that code and then jump back to where you are right now when finished. This can be done more quickly with a bookmark. Just bookmark the existing location by pressing Alt+Shift+F2. Now go to the other code you need to look at, and when you're finished, use F2 or Shift+F2 to go back to the previous code. When you have to jump among several sections of code, this can really be a time-saver if you mark each section with a bookmark.

Find dialog—escaping

Table 3
shows the effects that using the "\" character has in the Find dialog. It doesn't actually search for the backslash character; instead, it triggers the Find dialog to find other special characters.

Table 3. Using the "\" character in the Find dialog.

Char

Description

\t

Finds Tab characters

\r

Finds the end of each line

\n

Finds the beginning of each line

\\

Finds the "\" character

Both the "\r" search and the "\n" search have some quirks. Enter "\r" into the Find dialog and press the Find Next button. At first it may not appear as if anything is happening; however, keep pressing the Find Next button and eventually you'll see the highlight square in your code at the first blank line.

What's happening is that as the find goes to the end of each line of code, the cursor isn't highlighted—but it really is sitting at the end of the line. Each time you press Find Next, it goes to the end of the next line, but you don't have any visual clue until it hits another blank line. To prove that it really is working, activate the editor and type a letter. You'll see the letter at the end of the line. The same is true when doing a search for "\n" except the cursor goes to the beginning of each line. However, when searching with "\n" you don't ever see the cursor.

The "\\" search treats the first "\" as an escape and then treats the second "\" as the character being searched for. Therefore, searching for "\\" will find single backslashes. However, this really isn't necessary because a single backslash in the Find dialog will find all the backslashes.

Find dialog—wildcards

One of the checkboxes on the Find dialog is Use wildcards. Checking this option allows you to use special characters for wildcard matching. Table 4 shows what's available.

Table 4. Using special characters for wildcard matching in the Find dialog.

Char

Wildcard match

?

Single character

*

Multiple characters

#

Single digit

<

Match beginning characters

>

Match ending characters

[ ]

Character list

[!]

Exception list

The "?", "*", and "#" are pretty self-explanatory, but some of the other items need a bit more explanation. Searching for "<Fox" will find only those words that begin with "fox". If you have a variable named lcFox, this won't find it because it doesn't start with Fox. On the flip side, "Fox>" finds only those items that end with "fox". Therefore, it would find the lcFox variable, but it won't find a variable named lcFox1.

The "[" and "]" characters can be used together to find a list of items. For example, "lcFox[1-2]" will find variables named lcFox1 and lcFox2. Another example is "lcFox[1,2,4]", which will find lcFox1, lcFox2, and lcFox4. However, it won't find lcFox3.

Using the "!" along with the square brackets changes the meaning to be an exception list rather than the list you're looking for. Searching for "lcFox[!2]" will find lcFox1, lcFox3, lcFox4, and so on, but it won't find lcFox2. Similarly, "lcFox[!2-3]" will find lcFox1 and lcFox4, but it won't find lcFox2 and lcFox3.

IntelliSense

IntelliSense was introduced with VFP 7, and I can easily say that it's worth the price of the upgrade for just this one feature. Personally, I can't live without IntelliSense anymore. If I have to work on a pre-VFP 7 project, it drives me nuts. In fact, I usually do all my editing in VFP 7 or 8 and then use the older version just to compile it.

Operator expansion

With IntelliSense came a lot of keystroke-saving features, such as operator expansion. How many times have you typed lnCount = lnCount + 1? I swear that I've done it a million times by now. But these days, I can cut that typing to lnCount++, press the spacebar, and that's it. VFP will expand it out to what I want. Table 5 shows all of the operator expansion options available.

Table 5. Operator expansion options.

This...

Expands to this

cVar++

cVar = cVar + 1

cVar--

cVar = cVar - 1

cVar+=

cVar = cVar +

cVar-=

cVar = cVar -

cVar/=

cVar = cVar /

cVar*=

cVar = cVar *

IntelliSense hotkeys

I've seen a lot of developers start typing, take advantage of IntelliSense, and then realize they made a mistake. What they do next is start backspacing until they get back to the "." However, that's not necessary. Ctrl+J will list the members of the object without backing up to the period. You can also use Ctrl+J after the equal sign to list the values associated with a particular property. And Ctrl+I can be used to display Quick Info.

Put the following sample code into a program and then position your cursor as instructed and press the appropriate Ctrl+J or Ctrl+I to see how this works.

*-- Intellisense
LOCAL loForm AS Form 

*-- CTRL+J to list members
*-- (position cursor after the period)
loForm.

*-- CTRL+J to list values 
*-- (position cursor after the equal sign)
loform.alwaysontop = 
loForm.BorderStyle =

*-- CTRL+I for Quick Info 
*-- (position cursor on any of the parameters)
SEEK(cMyValue, cMyTable, cIndex)

Predefined "U" records

IntelliSense is completely extensible because everything is stored in a DBF table. You can view this table by entering USE (_FOXCODE) SHARED into the Command window. If you scroll near the bottom of this table, you'll see several records with a type of "U". The VFP team has preloaded several examples of how you can cut down on your keystrokes by entering records of these types. You can copy these records into new records and start adding your own for things you do on a regular basis.

Table 6 shows the predefined "U" records in VFP 8. Some of these work in the Command window and others work within the editor for programs and method code.

Table 6. Predefined "U" records in VFP 8.

This...

Expands to this

MF

Modify File

MC

Modify Command

DC

Define Class

Zdef

Show #DEFINEs

Zloc

Show local variables

DOCASE

DO CASE
CASE
OTHERWISE
ENDCASE

DOWHILE

DO WHILE
ENDDO

IFEND

IF
ENDIF

IFELSE

IF
ELSE
ENDIF

TRYEND

TRY
CATCH
FINALLY
ENDTRY

FOREACH

FOR EACH
ENDFOR

FOREND

FOR
ENDFOR

SCANEND

SCAN
ENDSCAN

TEXTEND

TEXT TO NOSHOW TEXTMERGE
ENDTEXT

WITHEND

WITH
ENDWITH

I encourage you to create your own "U" records to simplify your daily typing. It's probably no surprise to you that I've added a record to my _FOXCODE table to expand MR to MODIFY REPORT. Another change I make is to change the MF record to say MODIFY FORM instead of MODIFY FILE.

VFP tools and utilities

Visual FoxPro is full of many native tools and utilities to help you be more productive each and every day. Some of these have been around for years and years, and some are new to VFP 8. I'm not going to go to great lengths to describe how to use each of these tools, because each one could be an article in itself. I just want you to be aware of these tools so you can use them.

Class browser

The class browser has a few Most Recently Used (MRU) lists that you can access by RightClicking on the buttons. You can see MRUs for the Open button, the View Additional File button, and the Component Gallery button.

Using RightClick with the View Class Code button changes the behavior slightly. The editor window that appears with the code is smaller and fits within the right frame of the class browser. In fact, you can click on the View Class Code button to bring up the code for one class, and then use RightClick to bring up the code for a second class.

One of the most useful and lesser-known features of the class browser is its drag-and-drop abilities. Highlight a class in the class browser, and then drag the icon that appears in the upper left corner of the class browser to a form. The highlighted class is dropped on the form! You can also drag that icon to the Command window and the appropriate NEWOBJECT code is generated for you.

Debugger

Did you know that you can drag and drop from within the debugger? You can highlight a variable in the Trace window and then drag it to the Watch window. This can save you time since you don't have to type out long variable names, and it reduces the chances of a typo. You can also drag a variable from the Watch or Local window to the Command window or the editor.

Another great feature of the editor is that you can change the values of variables at will. Once a variable is in the Watch window or Local window, you can highlight the Value of the variable and type in whatever you want. This is great when you realize that something is set wrong and you want to continue running the program to see if the rest of it runs okay. In addition to typing the new value, you can also type an expression that gets evaluated immediately. For example, on a date variable, you can type DATE() and as soon as you press Return, the variable is set to the current date.

Code references—new to 8.0

In my opinion, this tool isn't named properly because it's really a giant search tool—one that works way beyond "just code." This tool lets you search through an entire project for a certain string. It can search programs, classes, reports, and all of the different files in a project. It also searches properties as well as method code.

Besides being a search tool, it's also a replace tool. You can actually tell it to replace all of the occurrences it found, or even specific occurrences. This makes massive changes to your application much simpler!

Task Pane—new to 8.0

The Task Pane is a portal to many different aspects of Visual FoxPro, including the Solutions Samples and the Visual FoxPro Community. As with many tools in Visual FoxPro, you can customize this tool until your heart's content. The customization can be passed back and forth between others by exporting and importing simple XML files. It's expected that many third-party tool and utility developers will offer their own add-ins to the Task Pane.

Toolbox—new to 8.0

The Toolbox can be considered a replacement for the Form Controls toolbar—on steroids! You can add all of your commonly used classes to this tool so that you can more easily design your forms. But it has some other advantages that aren't as well-known.

One category in the Toolbox is Text Scraps. It's meant to let you predefine a set of text and then paste it to your programs and method code. It's not just limited to VFP, though. You can also paste these text scraps to other applications, such as Microsoft Word.

One of the items you can add to the Toolbox is a file. However, you can use this feature to add some things that aren't really files. For example, add a dummy file and then change the properties to a URL. When you select this item from the Toolbox, Internet Explorer (or whatever browser you have set up) pops up and attempts to go to that URL. So if there are a few Web sites you visit on a regular basis during development, put them in the Toolbox for quick and easy access.

Another thing you can do with the file option is point to a directory. You have to first define a dummy file and then change the properties to go to the directory instead of the file. When you choose this option from the Toolbox, Explorer pops up already defaulted to that directory. If you find yourself navigating to the same directory all the time, add it to the Toolbox and save yourself some time.

Foundation classes

Take a look in the FFC directory within VFP's home directory (DIR HOME(1) + 'ffc\*.*') and you'll see tons of classes already defined for you. These classes were created by the VFP team to help you with your applications. Some of the classes are just subclasses of the VFP base classes. However, many others are classes that you can use within your applications, such as the class to display a progress thermometer.

Solutions samples

Enter the following command in the Command window and you may be surprised by what happens:
DO HOME(2) + 'solution\solution.app'

As you navigate through the tree structure, you'll see tons of examples of things you might want to do in your application. The user interface gives you the ability to run the sample or look at the code to see how it's done. This is a great learning tool for figuring out how to do things in VFP.

HexEdit

If you've ever needed to use a hex editor to hack a file, you'll know what a lifesaver this program can be. Or if your curiosity is driving you nuts, you can use the HexEdit program to peek at a DBF file and see exactly how it stores the data. This can be a great learning experience!

You can find this at C:\Program Files\Microsoft Visual FoxPro 8\Tools\HexEdit\hexedit.prg.

GenDBC

When you run this program, it creates all the code necessary to re-create your DBC. This can be great for helping you get a new application installed and created. No need to send all the data files. Instead, when you're ready to deploy your application, run this program on your machine and put the newly created program with your project. Have your installation program run the program generated by GenDBC, and the new installation will be up and running in no time.

It's also a great way to get one or two files copied into another DBC and retain everything about them. Run GenDBC on the original DBC. Then modify the program it created and strip out everything except the code that generates the few files you want. Change the name of the DBC in the program and rerun it to add these files to a different DBC.

You can find this at C:\Program Files\Microsoft Visual FoxPro 8\Tools\Gendbc\gendbc.prg.

xSource

Sometimes the best to way to learn about something is to dive into the code behind it. Many of the tools and utilities of VFP are actually written with VFP itself! The source code for all of those tools is included in a zip file stored in the C:\Program Files\Microsoft Visual FoxPro 8\Tools\xsource directory. When you have some time, unzip this file and start diving in to see how the VFP team has accomplished many great things in the native VFP tools and utilities.

"Ah ha"

I always enjoy writing about "tips and tricks" such as the ones in this article. Even experienced developers are bound to have some of those "ah ha" moments. There's so much in FoxPro that it's hard for any one person to know everything. In the next article of this series I'll cover the Command window, some commands, and a whole array of miscellaneous ideas.

To find out more about FoxTalk and Pinnacle Publishing, visit their Web site at http://www.pinpub.com/

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

This article is reproduced from the thismonth 2004 issue of FoxTalk. Copyright 2004, 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-788-1900.

Show: