Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Aborting a routine
Message
De
01/02/2017 02:29:22
 
 
À
31/01/2017 03:32:50
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
SAMBA Server
Database:
MySQL
Application:
Desktop
Divers
Thread ID:
01647222
Message ID:
01647242
Vues:
63
>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform