Rick Strahl's FoxPro and Web Connection Web Log
White Papers | Products | Message Board | News |

Using the VFP 9.0 Class Browser for PRG Files


Wednesday, January 3, 2007, 9:07:00 PM

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.

Posted in:

Feedback for this Weblog Entry


Re: Using the VFP 9.0 Class Browser for PRG Files



Sylvain Bujold
I tried this as I thought it would be really useful and it is with certain files but it seems that the Class Browser is really picky with parent class location and it fails to load in some situations.

Stuff like --CodeMarker-- does not work if MyClass definition comes from a different program file. Says an error like "Unable to display class hierarchy for:
class (MySubClass) of \wconnect\Classes\MySubClass.PRG
ParentClass (MyClass) of \wconnect\Classes\MySubClass.PRG

When really the parent class is in MyClass.PRG. I tried adding the full path in the AS clause of the DEFINE statement and it worked, but I won't change all my classes definition.

Re: Using the VFP 9.0 Class Browser for PRG Files


Yeah you're right and I agree. It even fails in many cases when the subclasses exist in the same PRG file which is really kinda lame. But I still find this very useful in many situations.

Re: Using the VFP 9.0 Class Browser for PRG Files



Sushil
As a VFP Lame It solved my ? , as how to open class in a prg

Re: Using the VFP 9.0 Class Browser for PRG Files


DO (_BROWSER) WITH GETFILE("VCX,PRG") works as well. And VFP "Open File" dialog much more powerful , than INPUTBOX().

re: Using the VFP 9.0 Class Browser for PRG Files



Eddy Maue
&& Execute for add CB


Select 0
Use (_foxcode) Shared
* ****************************************** ET
Append Blank

replace abbrev with "CB"

replace expanded with ""

replace cmd with "{}"

replace tip with ReplaceCaractere([])


replace data with ReplaceCaractere([LPARAMETER oFoxCode]+Chr(13)+;
[]+Chr(13)+;
[LOCAL lcCmdLine, lcClassName, lcFunctionName, lcOutput]+Chr(13)+;
[]+Chr(13)+;
[ ]+Chr(13)+;
[]+Chr(13)+;
[lcClassName = INPUTBOX(õClass Fileõ,õOpen Class Browser õ)]+Chr(13)+;
[]+Chr(13)+;
[ ]+Chr(13)+;
[]+Chr(13)+;
[oFoxcode.valuetype = õVõ]+Chr(13)+;
[]+Chr(13)+;
[ ]+Chr(13)+;
[]+Chr(13)+;
[IF EMPTY(lcClassName)]+Chr(13)+;
[]+Chr(13)+;
[ RETURN lcCmdLine]+Chr(13)+;
[]+Chr(13)+;
[ENDIF]+Chr(13)+;
[]+Chr(13)+;
[ ]+Chr(13)+;
[]+Chr(13)+;
[lcFile = lcClassName]+Chr(13)+;
[]+Chr(13)+;
[IF !FILE(lcFile)]+Chr(13)+;
[]+Chr(13)+;
[ lcFile = lcFile + õ.prgõ]+Chr(13)+;
[]+Chr(13)+;
[ IF !FILE(lcFile)]+Chr(13)+;
[]+Chr(13)+;
[ lcFile = lcClassName + õ.vcxõ]+Chr(13)+;
[]+Chr(13)+;
[ ENDIF]+Chr(13)+;
[]+Chr(13)+;
[ IF !FILE(lcFile )]+Chr(13)+;
[]+Chr(13)+;
[ return lcCmdLine]+Chr(13)+;
[]+Chr(13)+;
[ ENDIF]+Chr(13)+;
[]+Chr(13)+;
[ENDIF]+Chr(13)+;
[]+Chr(13)+;
[ ]+Chr(13)+;
[]+Chr(13)+;
[return ñDO (_BROWSER) with õò + lcFile + ñõò])

replace case with "M"

replace save with .T.

replace timestamp with Datetime()

replace source with ReplaceCaractere([RESERVED])

replace uniqueid with Sys(2015)

replace user with ReplaceCaractere([])

replace type with "U"
Use in FOXCODE

Procedure ReplaceCaractere(lcTxt)
Return Chrtran(lcTxt,Chr(241)+Chr(242)+Chr(243)+chr(244)+Chr(245),"[]'&"+Chr(34))

 



© Rick Strahl, West Wind Technologies, 2003 - 2018