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.

To make it even easier, the Clarion-style, here is a template that includes the source for you.
However, when you are new to Clarion, please set up a test application before, where you add the source manually. Then you might inspect the template source itself. Just to understand, what happens under the hood.
The template:

If you are new to Clarion, use following steps to add the template to your IDE (Clarion 10 or higher):
Extract the template from the ZIP to the directory, where all 3rd-Party templates are located.
in my case it is


Now open your IDE and go this path:
Main Menu => Extras => Edit Template Registry
Now click on "Register" and point to this directory, where the template sits.
When you create a new APP, you then simply add this DebugView-source via insert on "Global Extensions". Select wodbgview from the list. You can jump there by pressing the "w" or just by jumping to the very end.
Now you can use dbgview() in you APP.
In case you want to use it only on your development machine, but disable any Debug-output at your customers, you may use the global variable Global:DebugON, to toggle between 1 or TRUE and 0 or FALSE.
Set this variable based on a condition, like
IF EXISTS('drive:\path\yourProject.APP') THEN
    Global:DebugON = TRUE
    Global:DebugON = FALSE
or shorter
Global:DebugON = CHOOSE(EXISTS('drive:\path\yourProject.APP'), TRUE, FALSE)
Please note, this variable is not in the original source at the top of this page. I added it for the template. So, inspect the template and you will find it.

Page updated on 04. Nov. 2019

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