Debugging your Clarion APP with DebugView (Clarion 6.3)

Sometimes I wonder if everything in my programs run as I planned it. One easy way to follow-up what the EXE is just performing is to put a MESSAGE() or a STOP() in the source with some meaningful text. That way I can see whether a variable has got the right value or not
But that is a quite pedestrian and, I have to confess, rather clumsy way to "debug" a program.
With the help from the guys on the Clarion-Chat on Skype, namely Mark Goldberg and Olivier Cretey, I found a very easy way to improve my debugging.

First of all, you need a Third-Party-Tool called DebugView. It was written by Mark Russinovich and Bryce Cogswell, who distributed their tools under the label SysInternals for free. These guys were so smart that Microsoft finally hired them. Mark and Bryce agreed with Microsoft that their toolbox is continued and remains free! You can get the entire toolbox from this website which then redirects you to Microsofts TechNet. Go there and pick DebugView (its under "Miscellanous Utilities") or better get the entire Sysinternals Suite and install it on your machine!

Back to Clarion, your first step is to open Global Properties -> Embeds and insert this into your Global Map:

    dbgView(String DebugString)
The next step is to put the following into an embed in Program Procedures:

Clarion for Windows v6.0 to present

dbgView Procedure(String DebugString)  
DB  CString(SIZE(DebugString)+1)  ! define a variable that has the same size as the parameter we receive plus 1 character 
  DB = DebugString

Clarion for Windows v2.0 to present

dbgView Procedure(String DebugString)  
DB  &CSTRING  ! define a variable that has the same size as the parameter we receive plus 1 character 
  DB &= NEW CSTRING( SIZE(DebugString) + 1)
  DB = DebugString
Now you can use DebugView to watch right into your EXE using this new function dbgView()!

How to do that?

It is as simple as this: put that dbgView() with a somewhat meaningful text somewhere in your code - with a questionmark in front of it.

? dbgView('The LOOP starts in the very next line')
        IF somecondition THEN
? dbgView('somecondition found, Break should happen now')		
? dbgView('The LOOP has just finished at Record-No. ' & i)
You will now see the messages in your dbgView()-statements being displayed in the DebugView window.

Note the red colour of the questionmarks. This means, that they are in the first column of the source code.
When you do a final compile of your EXE with DEBUG OFF, then all source that begins with a questionmark will be omitted.

If you get too many information listed in DebugView, you may use a filter based on a string in the output. If you like, you could modify the DEBUG procedure by enhancing a prefix into the output.
   DB = 'MyExe: ' & DebugString

But in this case you also need to modify the length of DB
DB CString(SIZE(DebugString)+1+7) - because 'MyExe: ' needs these 7 extra characters. Otherwise your output in DebugView would miss the last 7 characters.

Now turn on the filter to include only output that holds "MyExe" you will see only those messages that are sent from your program.

Thats all! Add salt and pepper as you like....

You can download the sample source (Clarion 6.3 EE). This page was made on 16.05.2011.

DebugView works well with Clarion 5.5 also.

Dave Schwartz: "Well, I would say that this was a few minutes very well spent. 'DebugView' was just the leg up I needed in getting started."

Here you find some more samples