Solved

Stopping app in recursive loop?

Posted on 1998-01-30
5
144 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

751 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