Session E-SENS
Introduction to
Intellisense®
Contents
Intellisense lets developers speed through routine details, avoid spelling mistakes, and easily explore unfamiliar object models. This session will examine Intellisense as a new feature in VFP 7.0, and look at how it can be customized and extended by the developer. In addition, we will look at several IntelliSense-like products available for developers in Visual FoxPro 6.0 and earlier products.
This document was written based on an early build of the next version of Microsoft Visual FoxPro. It would not be unusual for certain of the features to change before the final release product. Please ensure that you test the features that you need, and refer to the current documentation, before trying to implement any of these features in your code.
Intellisense, a registered trademark of Microsoft Corporation, is an umbrella term used to describe the prompting th92,1ccurs when you type into command/immediate windows, code editor and snippet windows, and various debugging windows of Microsoft's development products. While the behavior seems similar in each of the products, each is implemented somewhat independently, and each has its own unique behaviors. In this paper, I focus on Visual FoxPro, but will mention where VFP features differ (usually for the better) from other Microsoft products.
Intellisense is designed to pop up windows of options for you to select from, in order to speed the process of entering code. In addition, selection from lists eliminates spelling errors. While many of the functions and commands that you will see while using Intellisense seem very similar, there are in fact, a number of different mechanisms at work:
Keyword expansion: typing "modi" and pressing space in the command window automatically expands to MODIFY.
Command completion: Once MODIFY is displayed, a list of command keywords appears (see Figure 1).
Most Recently Used (MRU): Use, Modify Command and Modify File bring up lists of most-recently used files (see Figure 2)
Quick Info: a small window, similar to a ToolTip, appears to coach you through supplying the clauses and parameters of commands and functions (see Figure 3).
List Members: Specifying an object, such as _VFP, and pressing the dot will bring up a list of members of that object. VFP's Intellisense will also do this with existing (instantiated) live objects while developing, but it is also smart enough to pop up these lists in code windows when the objects are strongly typed. See Figure 4, Figure 5, and Figure 6 respectively.
Figure 1: Command expansion changes 'modi' to MODIFY and Command Completion prompts for the next keyword
Figure 2: Most Recently Used (MRU) functions remember tables opened and files modified
Figure 3: Quick Info for the MessageBox Function
Figure 4: Listing Members of an internal VFP Object
Figure 5: Listing Members of a live COM object.
Figure 6: Listing Members of a class in a code editor, using strong typing.
IntelliSense fires when a specific keystroke fires it: for commands, the spacebar; for functions, an opening parenthesis, for member lists, the dot. The existing text on the line is parsed and compared against the existing objects, strongly typed objects, and keywords stored in the FoxCode table. When a match is found, the associated code is run.
To "UnDo" an automatic expansion, Ctrl-Z twice followed by the End key. To prevent command expansion, use Ctrl+Spacebar instead of a plain space. |
Strong typing is a characteristic of many languages where a memory variable must be declared to be of one specific data type, and attempting to later change that type, or assign an inappropriate value to the variable, will generate an error. Visual FoxPro, by contrast, is a loosely typed language, where private variables don't even need to be declared, and the datatype of variable can be changed on the fly. While this features has its benefits, it is much more difficult for IntelliSense to provide a lot of support to a loosely-typed language.
In the next version of Visual FoxPro, support will be provided to define memory variables of a particular, strong, type by using the AS clause:
LOCAL
loWord AS Word.Application
LPARAMETERS
loXTAB AS _xtab of (HOME(0)+"ffc\_\utility.vcx"
RETURN
loRetObj as _param of baseclass.vcx
References to those variables within the code window will produce appropriate prompts for that type of datatype or object.
There are a couple of new files, new memory variables, and new menu commands to make Intellisense work. We'll detail them here.
_FoxCode: system memory variable that stores the path and location of the FoxCode table used to supply keyword expansion, macros, data types, and more
_CodeSense: system memory variable that points to the main FoxCodeAPP file – an application that contains the routines for
_VFP.EditorOptions – a string to enable, disable, or modify the behaviors of Intellisense features. Typically, for each entry, an uppercase letter enables the function. A lowercase letter indicated it would not appear automatically, but be available via a menu shortcut key. See Table 1
Editor Option |
Function |
Notes |
L |
List Members |
Upper case L causes List Members to appear automatically. Lowercase L means that the List Members will only appear when selected from the menu (Edit|List Members) or the menu shortcut (Ctrl+J). Omitting the L altogether means that the List will not appear and the menu option is disabled. |
Q |
Quick Info |
List the List Members function, a capital Q displays Quick Info (prompting for parameters) immediately, while a lowercase Q means that Quick Info will only appear if selected from the Edit menu or the Ctrl+I shortcut. |
K |
Hyperlink |
Case doesn't affect this one. If upper or lower case is present, typing in typical internet addressed (www. or http:// or many of the others) in a code editor or the Command Window creates an active hyperlink that can be clicked to start a session. Unlike the other options, this is meant to work within the runtime as well! |
W |
Drag and Drop Between Words |
The default behavior for dragging and dropping text has changed between different versions of VFP, and now you have control over how you think it should work. In the default behavior (W not included), dragged text can be dropped anywhere. If W is specified, either case, text can only be dropped at the beginning of a word, and not in the middle of it. |
Table 1: _VFP.EditorOption values and their meanings
The FoxCode.DBF table contains the meta-data that describes how Intellisense should work. See Table 2.
Fieldname |
Datatype(Size) |
Purpose |
Type |
C(1) |
Identifies which type of record this is. Different records can use the other fields in different ways. (C)ommand expansion (F)unction expansion. (S)cript to be called from other items COM (O)bject type info (P)roperty of a VFP object Data(T)pes (V)ersion information – a special one-record entry in the FoxCode table. |
Abbrev |
C(24) |
Abbreviation – the minimum keystrokes that will uniquely identify this record, and invoke Intellisense. |
Expanded |
C(26) |
The command or function in ABBREV, expanded to its full text |
Cmd |
C(15) |
The command to execute. |
Tip |
Memo |
The Tool or Value Tip to display – parameters? |
Data |
Memo |
A storage place for code or data used by a script to expand this item. |
Case |
C(1) |
Whether the case is transmuted when returned: (U)ppercase the result (L)owecase the result (M)ixed (P)roper |
Save |
L(1) |
According to Help, "specifies whether the record is saved when the field updated." |
TimeStamp |
DateTime |
At last! A powertool that saves timestamps using the datetime function! |
Source |
Memo |
Not sure about this one. It is undocumented, and only contains the word "RESERVED" in my early version. |
UniqueID |
C(10) |
SYS(2015) – generated ID |
User |
Memo |
Presumably a field left for developers. A place to hook in DBCX-like functionality, perhaps. |
Table 2: The fields of FoxCode.DBF and their
functions.
Finally, the FoxCode object is an object passed to the script code to be executed (in type "S" records) and it exposes the parameters of the environment. All of the variables available in the FoxCode Record – Abbrev, Case, Cmd, Data, Expanded, Save, Source TimeStamp, UniqueID and User are present, as are a few other properties.
CursorLocChar is a string that holds a single character used as a marker to reposition the cursor at the end of the operation. Like CEE, mentioned below, the default seems to be the tilde {~} character.
DefaultCase holds the case setting of the Version header record, and is the default if nothing else is specified.
Filename holds the name of the file being edited, blank if in the command window or snippet editor.
FullLine contains the complete line of code being edited.
Icon, ItemScript, Items, and ItemSort are used to store the items in the dropdown list, present an icon for them, script how they are to work, and sort the list of items.
MenuItem: stores the selected item number from the dropdown, for use in a post-selection script
ParamNum is used for tracking parameters within the script. The Help file says it
UserTyped has the original text typed in by the user.
Up to this point, we've looked at what is provided by Microsoft. But the good news is that the IntelliSense engine and the metadata driving it are open for developers to extend in a number of ways.
First, consider using the IntelliSense Manager (Figure 7, Figure 8, and Figure 9). The IntelliSense Manager is available off the Tools menu, the Wizard menu (under "All Wizards…") and by issuing the command:
DO (_CODESENSE)
The Options tab allows setting the global settings for capitalization of commands and functions. It also is a place to perform routine maintenance:
Cleanup MRU Lists: removes files from the MRU lists if they no longer exist. Make sure that your network connections are running before you run this, or all of your network-based files will be removed.
Zap MRU Lists: removes all files from the list. The MRU lists are kept in the FoxPro resource table.
Cleanup FoxCode: "cleans up" the table. Presumably a PACK. Did not seem to do anything on my version.
Figure 7: The Options Tab of the IntelliSense Manager
Restore FoxCode: restores the developer's FoxCode table from the master table kept in the VFP root directory.
Import: allows the addition of more records to the FoxCode table. Records have a matching structure to the FoxCode table. See HOME() + "Tools\FoxCode" for some add-on tables.
View FoxCode: allows live editing of the table in a browse window.
Figure 8: The Types Tab of the IntelliSense Manager
The second tab on the IntelliSense Manager allows for the
maintenance of the data type ("T") records. These include all of
VFP's bases classes, as well as a types we may not be familiar with: Decimal,
Boolean, Variant and VOID. Unchecking
the box at the left of each column flags the record for deletion in FoxCode.
Checking it again restores the record.
Finally, the Customize Tab on the IntelliSense Manager allows for the editing and maitenance of
Figure 9: The Customize Tab of the IntelliSense Manager
While the next version of Visual FoxPro is still some ways off, you can have many of the features available in IntelliSense in the current version of FoxPro. Two programs are included on the conference CD: CEE and ISX
CEE, the Cob Editor Extensions, was written by veteran DevCon speaker Randy Wallin and co-worker Ryan Katri of COB System Designs, Inc. (http://www.cobsystem.com) and is available for free download from their website. CEE provides keyword expansion (although you have to fill in the table yourself), macro capabilities, recursive evaluation (so a macro can contain a macro that contains a macro, and so forth). Versions are available for FoxPro 2.x and each major version since.