You will need a second thread to solve your problem. In a nutshell: 1. Display a modal dialogbox with a cancel button - this provides your "block". 2. Run the lengthy process on a separate thread, but at regular intervals, check that the thread is terminated, and if it is, exit out of the execute method. 3. The cancel button terminates the thread 4. The thread closes the dialogbox just before it exists from the execute method. 5. Optionally, you can have the thread periodically update dialog, eg. display progress.
HTH, Dennis. ----- Original Message ----- From: Donovan J. Edye To: Multiple recipients of list delphi Sent: Friday, February 14, 2003 12:12 PM Subject: [DUG]: [Q] A design issue... G'Day, I have been trying to come up with an elegant solution to something but have not had any success. Some suggestions and comments would be most welcome. This is the scenario: 1. Application is single threaded 2. Makes call to a procedure that is very intensive (say a recursive scan of a directory tree) Now I dont want the 2. call to return until it has completed what it is doing. However as it utilises 100% CPU the main application suffers. So how do I work around this? Possible Solutions a) Provide a callback in the 2. procedure so that the application can do something about things. Say call Application.ProcessMessages This is OK, but it would be nice if the caller of 2. did not have to do anything. So I guess my question is. How do I change 2 so that it: - Co-Operates nicely with its caller in terms of resource usage - Blocks until it finishes Is it somehow possible to kick off a thread in 2. but still have it block until it finishes what it has to do? I hope this is clear. Any comments, suggestions welcome. -- Donovan ---------------------------------------------------------------------- Donovan J. Edye [www.edye.wattle.id.au] Namadgi Systems [www.namsys.com.au] Voice: +61 2 6285-3460 Fax: +61 2 6285-3459 TVisualBasic = Class(None); Heard just before the 'Big Bang': "...Uh Oh...." ---------------------------------------------------------------------- GXExplorer [http://www.gxexplorer.org] Freeware Windows Explorer replacement. Also includes freeware delphi windows explorer components. ---------------------------------------------------------------------- --------------------------------------------------------------------------- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi" Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/