Solved

Stopping app in recursive loop?

Posted on 1998-01-30
5
143 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
find a node in VST 2 78
HTML text in the body of an email (delphi code) 12 210
Browsing a TTreeView in Delphi 5 32
Add New Database Table in database file using delphi 3 29
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

749 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