Using the VFP 9.0 Class Browser for PRG Files
January 03, 2007 •
This isn’t exactly news, but in Visual FoxPro 9.0 - unlike in previous versions - the Class Browser works with PRG classes which is very nice if you have PRG files with complex classes or multiple classes. I’ve known this for some time, but the CB is not exactly obvious to work with and there’s always the document window right?
Well, the Class Browser is a lot more useful than the Document Outline functionality from the Tools menu, because it not only shows you the methods of the PRG file but also properties. It’s a much cleaner view of your classes in a PRG file especially if your PRG file holds multiple classes or classes with many properties. How many times have you worked on your class and tried to remember the name of a property only to have to navigate up in the source, look up the name and then go back? The Class Browser lets you see the class as a whole at a glance.
Ok, but it’s a pain to get to the Class Browser right? Well, not really. You can use the command line:
DO (_Browser) WITH "webcontrolsAjax.prg"
That’s easier. Even better create an Intellisense script that prompts for filenames and checks extensions automatically:
LPARAMETER oFoxCode
LOCAL lcCmdLine, lcClassName, lcFunctionName, lcOutput
lcClassName = INPUTBOX("Class File","Open Class Browser ")
oFoxcode.valuetype = "V"
IF EMPTY(lcClassName)
RETURN lcCmdLine
ENDIF
lcFile = lcClassName
IF !FILE(lcFile)
lcFile = lcFile + ".prg"
IF !FILE(lcFile)
lcFile = lcClassName + ".vcx"
ENDIF
IF !FILE(lcFile )
return lcCmdLine
ENDIF
ENDIF
return [DO (_BROWSER) with "] + lcFile + ["]
Add a record to your (_FoxCode) table then set the type to U, choose a shortcut (say CB) put {} in the CMD field, and the above code into the Data field.
Now when you type CB {ENTER} into the command window an input box prompts for a filename. If the file is in your path just type the name (ie. wwHttp or wwIpStuff). Type just the name of your PRG (or VCX) file and up comes the class browser...
If you want to take this a step further and have it pop up directly from your Class or PRG file you can create a file like this and hook up a shortcut key (unfortunately you can’t create ON KEY LABEL expressions like ON KEY LABEL ALT-T-D).
ON KEY LABEL ALT+B DO ShowClassBrowser in ShowClassBrowser.prg
FUNCTION ShowClassBrowser()
LOCAL lcWin, lcVcx, lcClass, lcFile
lcWin = WONTOP()
IF FILE(lcWin)
DO (_Browser) WITH lcWin
RETURN
ENDIF
IF ATC(".vcx",lcWin) > 0
lcVcx = ALLTRIM(STREXTRACT(lcWin,"- ","("))
IF FILE(lcVCX)
lcClass = STREXTRACT(lcWin,"(",")")
DO (_browser) WITH (lcVcx),(lcClass)
RETURN
ENDIF
ENDIF
lcFile = INPUTBOX("Class File","Open Class Browser ")
IF EMPTY(lcFile)
RETURN
ENDIF
IF !FILE(lcFile)
lcFile = lcFile + ".prg"
IF !FILE(lcFile)
lcFile = lcClassName + ".vcx"
ENDIF
IF !FILE(lcFile )
LOCAL lcOldDir
lcOldDir = SYS(5) + CURDIR()
lcFile = GETFILE("prg;vcx","Class File","Find Class",0,"Find Class")
CD (lcOldDir)
IF EMPTY(lcFile)
RETURN
ENDIF
ENDIF
ENDIF
DO (_BROWSER) with (lcFile)
ENDFUNC
Now it’s a cinch to bring up the class browser...
There's one annoyance with the Class Browser and that's if you clear your environment (CLEAR ALL or RELEASE ALL) the CB goes with it unlike the Document View which is always automatically active. But that's minor if you can quickly bring up the browser.
Sylvain Bujold
January 05, 2007