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 Edit an existing label Forms Designer Drilling into containers 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.
Grid controls Grids have always been somewhat difficult to work with, especially for new developers, because some things just aren't intuitive. Adding controls 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 Navigation 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.
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 Case Bookmarks Find dialog—escaping Table 3. Using the "/" character in the Find dialog.
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 Table 4. Using special characters for wildcard matching in the Find dialog.
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 Table 5. Operator expansion options.
IntelliSense hotkeys 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 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.
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 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 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
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 Toolbox—new to 8.0 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 Solutions samples 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 You can find this at C:/Program Files/Microsoft Visual FoxPro 8/Tools/HexEdit/hexedit.prg. GenDBC 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 "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. |