Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

SET EVENTTRACKING, Set(“EventTracking”), SET EVENTLIST, Set(“EventList”)

These commands let you programmatically control all the same features managed by the Debugger’s Event Tracking dialog. Well, almost all of them, anyway.

Usage

SET EVENTTRACKING ON | OFF | PROMPT
cTrackingStatus = SET( "EVENTTRACKING" )
SET EVENTTRACKING TO [ FileName [ ADDITIVE ] ]
cTrackingFile = SET( "EVENTTRACKING", 1 )
SET EVENTLIST TO [ EventList [ ADDITIVE ] ]
cEventsTracked = SET( "EVENTLIST" )

Let’s get the most important item out of the way first. SET EVENTLIST and SET EVENTTRACKING have the same four-letter (and, in fact, five-letter) abbreviation. Which one wins if you type just SET EVEN or SET EVENT? SET EVENTTRACKING. You need at least SET EVENTL for SET EVENTLIST.

When you’re trying desperately to figure out what’s going wrong in a program, event tracking can be a lifesaver. It lets you see what events are firing, in which order, without having to go into each one of them and add a DEBUGOUT statement. However, given the incredible assortment of events available, you don’t really want to see all of them. Consider the number of MouseMove events fired by a single move of the mouse from one object to another, for example. So SET EVENTLIST lets you decide which events should be tracked. Use the ADDITIVE keyword to add another event or two to the current list. Unfortunately, there’s no easy way to remove just one or two events, but leave the rest. (You have to either retype the list or grab the current list with SET(“EVENTLIST”), use STRTRAN() to remove the offender, and issue a new SET EVENTLIST.)

We ran into one interesting trap with SET EVENTLIST. If you specify only a single event, you can put quotes around the event name or not—your choice. As soon as you have more than one in the list, surrounding it with quotes gets you a Syntax Error. (However, if you really like typing extra characters, you can surround the individual items in the list with quotes. Just make sure the commas are outside the quote marks. Not that we can think of any reason to do it this way.)

So, once you’ve set the event list to the ones you care about, how do you actually track them? First, you have to actually turn on event tracking. Ordinarily, it’s off.

By default, the messages indicating which event of which object fired appear in the DebugOutput window. There are two ways to get that information into a text file instead. You can redirect all the Debug Output information with the SET DEBUGOUT command. If all you want to put in a file is event-tracking data, use SET EVENTTRACKING TO filename, instead. ADDITIVE, of course, says to leave the file alone and just stick the new information at the end.

Once you put the event data in a text file, you can, if you want, do things like import that data into a table and compute various statistics. This might be a good choice when you’re trying to figure out which methods are worth optimizing. Find out which ones fire the most and slim them down. Take a look at SET COVERAGE for more help in this regard. The PROMPT option of SET EVENTTRACKING brings up the Event Tracking dialog. If the Debugger is open in its own frame, that frame comes to the top. You can’t combine the PROMPT option with either ON or OFF. The keyword that appears first takes precedence and the other is ignored.

One item in the Event Tracking dialog isn’t accessible by command. With the dialog, you can specify that the data goes only to the file you name and not to the Debug Output window. There’s no command equivalent for that one.

Example

SET EVENTLIST TO Load, Init, Click
SET EVENTTRACKING ON
* Run a form
SET EVENTTRACKING OFF
SET EVENTLIST TO

* To remove a specific event from the
* tracking list, do something like:
cList = SET("EVENTLIST")
cList = STRTRAN(cList,cEvent,"")
cList = STRTRAN(cList,", ,",",")
SET EVENTLIST TO &cList

See Also

Debug, DebugOut, Set Coverage