Saturday, May 13, 2006

Debugging Tip

At GLGDW 2006 there was a panel session on Debugging Best Practices and Tips. I was on the schedule, but was preempted when Doug needed a machine to do his vertical market session and used mine. So I thought I would present it here instead, although I think Dan Freeman mentioned it breifly during the session.
 

A Visual FoxPro developer can go through a lot of work configuring the debugger with the settings for the watch window, developing the exact breakpoints needed for an application or module, and selecting certain events to be tracked. The settings can change depending on the application or a specific module in an application. We can delete expressions from the watch window and enter in new ones as we test various modules, we can toggle breakpoints in use and not in use, and we can move events that are tracked on and off the list. Another way is to save the exact configuration for the module and later load the configuration without the need to reenter the expressions or toggle the breakpoints.

This is accomplished via the Debug frame only. Using the menu, you can select the File | Save Configuration… to create a file. The file save dialog will default to the current Visual FoxPro directory. To restore a previous configuration you use the File | Load Configuration… menu option. The file contents are stored in an ASCII text file. Here is an example:

DBGCFGVERSION=4

WATCH=_screen

WATCH=set("deleted")

WATCH=set("path")

WATCH=thisform

WATCH=curdir()

WATCH=recno()

WATCH=eof()

WATCH=_vfp.ActiveProject

BPMESSAGE=OFF

BREAKPOINT BEGIN

TYPE=2

CLASS=    

LINE=0

EXPR=EOF("curReport")

DISABLED=0

EXACT=0

BREAKPOINT END

 

BREAKPOINT BEGIN

TYPE=3

CLASS=    

LINE=0

EXPR="MAIN"$PROGRAM()

DISABLED=1

EXACT=0

BREAKPOINT END

 

EVENTWINDOW=ON

EVENTFILE=

EVENTLIST BEGIN

Activate, Deactivate

EVENTLIST END

 

You can manipulate the contents safely in a text editor and reload the configuration. Make backups of this file if you are worried of breaking the layout.

The really cool thing is these files can be created programmatically. Watch expressions are single line entries and can be in any location in the file. So you can easily add a watch with a simple line of code:

STRTOFILE("WATCH=ALIAS()", ;

          "MyDebugSettings.DBG", 1)

 

You also can sort the Watch expressions in the file. One of the things bugging me (no pun really intended) in the Watch window is new expressions are added at the bottom of the list. You can add them to the top of the expression list programmatically in the file using this code:

 

lcFileContents = FILETOSTR("MyDebugSettings.DBG")

STRTOFILE("WATCH=ALIAS()" + CHR(13) + lcFileContents, ;

          "MyDebugSettings.DBG", 1)

 

Once you add it you have to reload the configuration file. One disadvantage to this approach is you lose the IntelliSense capability of the Watch window.

 

Each time I have talked to developers about this feature someone comments to me how they never knew it existed.

0 Comments:

Post a Comment

<< Home