Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Aborting a routine
Message
From
01/02/2017 02:29:22
 
 
To
31/01/2017 03:32:50
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
SAMBA Server
Database:
MySQL
Application:
Desktop
Miscellaneous
Thread ID:
01647222
Message ID:
01647242
Views:
62
>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
Previous
Reply
Map
View

Click here to load this message in the networking platform