Solved

Stopping app in recursive loop?

Posted on 1998-01-30
5
140 Views
Last Modified: 2010-04-04
Can someone tell me how to stop an application when a recursive loop is running? For example, if I am recursively reading through an entire disk (which takes a long time), and I click the "Close" button, nothing happens.  I want to be able to stop everything and just shut down. I thought I had this figured out, but to no avail. :-)  
0
Comment
Question by:jexd99
5 Comments
 
LVL 4

Accepted Solution

by:
d003303 earned 50 total points
ID: 1358031
Yo,

define a global break-flag that is false initially. Set it to true in the OnCloseQuery-event of the form.
In your recursive loop, add the line Application.ProcessMessages and check for the break-flag. Exit the loop if the flag is true.

Slash/d003303
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1358032
You can do it with threads. -Look at the sorting example taht D3 or D2 has in the \demos\threads dir.
If you want to terminate a thread you just call the .Terminate method and that means taht your recursive proc will also terminate.

Good luck!
Matvey
0
 

Expert Comment

by:michael2010898
ID: 1358033
If the program responds to the button click you
can use application.terminate
If not then use thread for the procedure and when the user
clicks the button use .Terminate if you want to stop
the procedure or use .Supend to supend it and then you will be
able to continue it with .Resume.


0
 
LVL 4

Expert Comment

by:d003303
ID: 1358034
Threads might be a better solution than mine. You could also recurse through several disks the same time, just start a second instance of the thread object. Like Matvey said, the sorting example is worth a look.
If want to use threads, don't hesitate to reject my answer.

Slash/d003303
0
 

Author Comment

by:jexd99
ID: 1358035
Thanks for the info. :)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Using idhttp to login to instagram 2 89
Print Graphic and Text to Epson TM-T88v 12 259
Controlled Assessment GCSE - desperate help needed 4 85
Delphi Yen format 3 35
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question