Wednesday, November 30, 2005

FoxPro Tips: Class Browser

At the recent German DevCon I presented my "Get Productive with Visual FoxPro" session. This session is always different each time I give it. Mostly because the people attending the session often participate by throwing in their own productivity tips (which I encourage in all my sessions). I always start the session off with productivity tips with the Class Browser tool which ships with VFP (and has since VFP 3). It rarely fails that a developer will contact me after the session to let me know how much they appreciate the various tips on the Class Browser.

So in case you have not seen the session, here are some of the tips:

Set the default file to be opened when Class Browser is started

First open up the Class Browser and open up the class library you want to be the default class library opened when the Class Browser starts. In the Command Window:
_oBrowser.SetDefaultFile()

If you want to clear the default class library execute the following statement:
_oBrowser.ResetDefaultFile()

This works great if you are constantly editing classes from the same class library for an extended period of time.

You can open the Class Browser with multiple class libraries

The first parameter accepted by the Class Browser is the file name of the VCX, or more accurately a comma-delimited list of VCX file names.

DO (_browser) WITH "examples\CPhkBase2, examples\demo"

Most Recently Used List

Have you ever right-clicked on the open button of the Class Browser? If not, give it a try and see a long list of previously opened class libraries. This has been in the tool for years, but I still show developers this little trick which saves me hours of drilling through directory structures.

Project Manager Can Start Class Browser

Double-clicking in the Project Manager on a Visual Class Library will open the class library in the Class Browser in VFP 9. Previous to VFP 9 nothing happened when you double-clicked on a class library. You can stop this from happening via a projecthook QueryModifyFile event. You can also intercept this in a projecthook via the QueryModifyFile event and run your own class library tool, or you favorite hacking tool like HackCX Professional (code to do this is posted here for HackCX Pro users).

Class Browser can open/maintain PRG based classes

The Class Browser has always been able to open VCX files, but many developers prefer to code their classes in program code (PRG). One of the disadvantages to taking the PRG route was the inability to use the Class Browser to maintain the classes and get a visual representation of the class hierarchy. Visual FoxPro 9 removes this limitation.

Renaming methods and properties without opening the class

You can rename methods and properties by right-clicking on the property or method and selecting Rename... on the shortcut menu. A dialog is presented which allows you to rename the property or method. Please remember that renaming a method or property does not magically rename the references in the method code. You will need to manually search and replace any references that are changed.

Copying and Moving Classes Between Class Libraries

You can open two instances of the Class Browser and use the mouse with the Ctrl key pressed to drag the icon in the upper left corner to the other instance of the Class Browser. This will copy the class to the other class library. This will maintain the same parent class relationship. If you do not hold down the Ctrl key you will move the class to the other class library.

It is not uncommon when I show this to developers to hear how they are surprised you could run multiple instances of the Class Browser. To me, this is one of the more powerful features of this important tool.

I posted the last one yesterday on FoxForum.com and a friend of mine popped me an email today noting this was cool and I should post this on my blog (prompting this entire post). Heck, how could I just pay it forward with one tip when I have so many others? So thanks Mary, it is all your fault this knowledge gets spread further into the Fox Community {g}.

Enjoy!

4 Comments:

At 12/01/2005 02:07:00 PM, Anonymous Mary said...

Thanks for all the tips, they are appreciated! Now I might be tempted to comment on one of your postings each month {g}.

 
At 12/02/2005 02:11:00 PM, Anonymous Alex Feldstein said...

Great tips Rick! I learned a new one today. Made my day!

Blogged about it:
http://www.bloglines.com/blog/AlexFeldstein?id=577

 
At 12/02/2005 03:31:00 PM, Blogger Rick Schummer said...

You are both welcome. More tips to come (and hopefully more inspiration from Mary!).

 
At 12/05/2005 08:51:00 PM, Blogger Toni M. Feltman said...

Thank you. I love the SetDefaultFile() tip. Now, if you could just open several and use SetDefaultFile to remember them all. It only remembers the last one. Bummer.

 

Post a Comment

<< Home