>Hi All,
>
>Is it possible to 'abort' some processing loop? I tried the code below (form method) to no avail:
>
>
>
>ON ESCAPE ThisForm.QuitProcess = .T.
>
>ThisForm.QuitProcess = .F.
>
>BEGIN TRANSACTION
>
>DO WHILE NOT ThisForm.QuitProcess
> * here, we do stuff like calculations, record inserts
>ENDDO
>
>IF ThisForm.QuitProcess
> ROLLBACK
>ELSE
> COMMIT
>ENDIF
>
>
>Thanks in advance!
Adding to other suggestions, you may treat user escaping as an exception and exit the process at any time.
LOCAL TestForm AS FormWithLengthyProcess
LOCAL Catcher AS Exception
m.TestForm = CREATEOBJECT("FormWithLengthyProcess")
m.TestForm.Show()
TRY
SET ESCAPE ON
ON ESCAPE ERROR "Interrupted"
m.TestForm.LengthyProcess()
CATCH TO m.Catcher WHEN m.Catcher.ErrorNo = 1098 AND m.Catcher.Message == "Interrupted"
m.TestForm.Aborted = .T.
CATCH TO m.Catcher
MESSAGEBOX("Something bad happened while process was running")
FINALLY
ON ESCAPE
ENDTRY
MESSAGEBOX("Process ran to " + TRANSFORM(m.TestForm.DisplaySomething) + " and it was " + ;
IIF(!m.TestForm.Aborted,"not ","") + "aborted")
m.TestForm.Release()
DEFINE CLASS FormWithLengthyProcess AS Form
DisplaySomething = 0
Aborted = .F.
PROCEDURE LengthyProcess
This.DisplaySomething = 100000
This.Aborted = .F.
DO WHILE !EMPTY(This.DisplaySomething)
WAIT WINDOW TRANSFORM(This.DisplaySomething) NOWAIT
This.DisplaySomething = This.DisplaySomething - 1
ENDDO
WAIT CLEAR
ENDPROC
ENDDEFINE
----------------------------------
António Tavares Lopes