Clarion Help and Examples


DiskSum

(Download Disksum.zip 25k) This example program will scan your disk and give you a summary of the disk space used. One thing it does that I have not seen before is show the total space used by a branch. It's a handy utility and it demonstrates the below Clarion programming techniques. The App file is included.

For some processes it can be difficult to do it the way the Clarion Process template does with the Timer Event driving the process. But you want the Timer so that you share timeslices with other Apps and check for a user cancel. To read a disk tree I was using a recursive call. It would be difficult or impossible to do.

The solution is simple. Back in the DOS days of CPD you would probably DO CheckCancel frequently in your code. You can do the same thing in CW. In the CheckCancel Routine have your Accept loop. When the Timer event occurs break out of the Accept loop and exit the routine to resume processing. You can also check if the user pressed the Cancel button. Here is some sample code for this routine:

AcceptRtn   ROUTINE     
	!IF you put the Accept Loop in a Routine you can have your logic
        !DO it periodically to check to see if the user has
        !Pressed cancel instead of having your logic called by the
        !timer event. It is important to BREAK out the the Accept loop
        !and not just EXIT the routine. This leaves the Accept loop going
        !and will GPF eventually. Also Open the window somewhere.
    CancelFlag = 0
    ACCEPT
        CASE EVENT()
        OF EVENT:TIMER
            BREAK
        OF EVENT:CLOSEWINDOW
	    CancelFlag = 1
            BREAK
        OF EVENT:ACCEPTED
            IF FIELD()=?CancelBtn
    	       CancelFlag = 1
               BREAK
            END
        END
    END

    IF CancelFlag               !User Cancelled
           Message('Are you sure you want to cancel?...
           RETURN
    END

PROP:Touched and Cancel

Do you ever use PROP:Touched to force entry of a field? The problem is that then the user cannot press the Cancel button without causing you to get an Accepted event. And you cannot tell that he pressed Cancel. There is an easy fix. Use an Alert key, alert events come first:

  1. On your Cancel button ALRT(MouseLeft)
  2. In the EVENT:AlertKey embed for Cancel add POST(EVENT:Accepted,?Cancel)

Copyright 1998, All rights reserved, Carl T. Barnes.
Last revised: October 12, 2001.