For a while, I’ve had a simple little debug class that let’s me output messages to the debug window or to a text file. For example in my application that sends an email, if the sending fails for some reason, I create a little text file the user can send me:

if !oMail.Send()

local oDebug

oDebug = newobject(“DebugX”)

oDebug.Message(“Email Failed”)

oDebug.Message(“Email address was: ” + oMail.cSendTo)

oDebug.Message(“Error message was: ” + oMail.cErrorMsg)


This class has a couple little interesting features:

  • As noted, the message function can send to the debug window or to a text file. Just set the .cOutputType property.
  • Every .Message() gets a date + time stamp so I know when it happens.
  • I know this never happens to you, but I sometimes forget to remove the debug code before sending to production. This class has a lIsDevelopement property. If it’s not developement, then the .Message() doesn’t do anything.

Tamar‘s talk about speeding up Foxpro code at Southwest Fox prompted me to add a couple new functions:

  • Added a .Start() and .Stop() to start/stop a timer. Any .Message() that is sent while the timer is going will include the elapsed seconds. This works correctly over Midnight as well.
  • Added a .Loop() function that will loop a .nLoop number of times. This is handy if one pass through your code is not enough to accurately time how long it takes. If you accidentally leave this code in for production, nLoop always resets to 1.

So you can do things like:

local oDebug

oDebug = newobject(“DebugX”)

oDebug.Message(“Debug Starting”)

oDebug.Start(“Start timing some code, Loop 4 times”)

oDebug.nLoop = 4

do while oDebug.Loop()

oDebug.Message(“Pass # ” + tran(oDebug.nLoop))

<some Foxpro code I want to time >


oDebug.Stop(“End of debugging test”)

Here’s the code:

One thought on “DebugX

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s