home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
FOXPRO
/
TASKDE
/
TASKDEMO.DOC
< prev
next >
Wrap
Text File
|
1993-12-26
|
5KB
|
141 lines
TASKDEMO.DOC
DECEMBER 28,1993
The TASKDEMO.PRG program uses a FoxPro binary file called INTERVAL.BIN
to stuff the Keyboard buffer at any interval you specify. INTERVAL.BIN is
based on TIMEOUT.BIN by Paul Saffren. TIMEOUT.BIN is available on
Compuserve. INTERVAL.BIN can be used as a one shot timer like TIMEOUT.BIN
or as a continuous interval timer. TASKDEMO.PRG is an extreme example of
using the interval timer to simulate a multi-tasking environment in FoxPro.
A more usual application of the interval timer would be to check for some
condition every 10 minutes or so. e.g - See if a file has arrived in a
network directory or seek on a shared database file. Unfortunately there
are severe limitations on what can be done while using the interval timer.
The usefulness of the interval timer depends on the application involved and
the type of activity that is going on in the foreground. In the case of
the TASKDEMO.PRG many hoops must be jumped through.
The main problem is that when you are editing a GET field and execute
a user defined function by pressing an 'ON KEY LABEL' key and return
to editing, the cursor has returned to the beginning of the field. Since you
don't know when the interval timer is going to stuff the key and call your
UDF you may be right in the middle of editing a field when the cursor returns to the begining of the field. This is not a large problem if the
interval is a long one e.g. - 5,10,15 minutes. The TASKDEMO program gets
around this problem by useing EDIT fields instead of GET fields. EDIT fields
maintain the cursor possition during UDF calls. But! it seems that with
single line EDIT fields the cursor position is not maintained if the
character to the left of the cursor is a Space (32) character. TASKDEMO
gets around this by using ASCII (255) characters instead of space characters
while editing a field and then replaces them with spaces on exiting the
field. (Kludge, but it seems to work)
Like I said, TASKDEMO is an extreme example in that it allows the
user to type away while fields are updating and windows are opening and
closing in the background. In a more typical application there may be
no reason not to turn off the timer while the user edits a field. If you
are not actually editing a text type GET field there seems to be no
problems running the timer at a high interval e.g. 1 second. The AMOUNT
field in the demo is a regular Numeric GET field. The Timer is turned
off by the field's WHEN clause and restarted by the VALID clause.
I didn't use FoxPro Button controls because I think the psuedo Buttons
work cleaner, but regular buttons will work no problem with the interval
timer. (The Confirm Quit window uses regular buttons).
Actually it seems you can edit records in a BROWSE or a CHANGE screen
with no adverse effects when using the interval timer. You just have to
ACTIVATE the browse window with the last statement of your UDF if you are
doing output to a diffent window.
DETAILS ON USING INTERVAL.BIN
INTERVAL.BIN is a modified version of TIMEOUT.BIN by Paul Saffren.
Paul has released TIMEOUT to the public domain and INTERVAL.BIN is also
public domain. INTERVAL.BIN was assembled with Turbo Assembler 3.2
To use INTERVAL.BIN in a program include the following in the setup code
of your program.
LOAD INTERVAL.BIN
To start the timer:
CALL INTERVAL WITH '182,126'
The parameters must be given as a single string. In the case above
INTERVAL will stuff the keyboard with the tilde character '~' every
10 seconds. The first half of the parameter (182) is the number of
timmer ticks to count before stuffing the key. The PC's timer ticks
18.2 times a second. 18.2 x 10 is 182, exactly 10 seconds. 91 would
be exactly 5 seconds. Do not pass decimal numbers like 18.2 for exactly
1 second, use 18 or 19. Integers only.
The second part of the parameter is the decimal ASCII code for the
key you want to stuff between 0 and 255. If you do not specify a key
the default is 27 (Escape). e.g. - CALL INTERVAL WITH '182'
To call your timer routine:
ON KEY LABEL ~ DO MyTimerRoutine
I like to use the tilde ~ character because it is seldom used.
A sample timer routine:
PROCEDURE MyTimerRoutine
DO This
DO That
DO OtherThing
RETURN
To stop the timer:
CALL INTERVAL WITH '0'
Note: You MUST make this call before exiting your program.
To Unload INTERVAL from Memory:
RELEASE MODULE INTERVAL
Example program shell:
LOAD INTERVAL.BIN
ON KEY LABEL ~ DO MyTimerRoutine
CALL INTERVAL WITH '182,126'
DO DefineMyGets
READ
ON KEY LABEL ~
CALL INTERVAL WITH '0'
RELEASE MODULE INTERVAL
Example of a one shot timer:
LOAD INTERVAL.BIN
ON KEY LABEL ~ DO MyTimerRoutine
CALL INTERVAL WITH '182,126'
DO DefineMyGets
READ
ON KEY LABEL ~
CALL INTERVAL WITH '0'
RELEASE MODULE INTERVAL
PROCEDURE MyTimerRoutine
CALL INTERVAL WITH '0'
DO Something
RETURN
IF your program is going to be performing a lengthy operation e.g. -
run a report or doing a LOCATE on a large file remember to stop the
timmer until the procedure returns.
Ed Duchesne