Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enable a locked form? 1

Status
Not open for further replies.

rcloutie

Programmer
May 26, 2005
164
CA
Hi,

I have a standard form (FixedToolBox) in which 2 controls are visible: a ProgressBar and a Cancel button.

When the program is processing a long operation (like copying some files from a network disk to local), I want to let the user to cancel the operation. The problem is that both control and cursor seem busy: that is, the cursor is Hourglass (not set by me?) and clicking the button does not generate click event...

Any ideas of how to enable a locked form?

Thanks in advance,
 
It depends on exactly how you have coded your procedure. If you are running a simple loop then you can have a cancel variable which is set when you click the cancel button. When you hit the end of a loop cycle, call Application.ProcessMessages and then check on the state of your variable. If your variables tells you to cancel, then just Abort the looped procedure.

If however your procedure is not looped and is quite long and complex, then the clenaest way to do this would most likely be with a thread. If you run your procedure in a thread then the rest of your program operates normally outside of the thread which of course includes your cancel button. In your cancel button, you would then simply need to terminate the running thread in order to cancel the procedure.

Theres loads of posts on the sunject of threads in this forum and they are also covered quite well in the Delphi Help guide. Shout back if you get stuck and Im sure we can help you out.

[blue]"Now you see that evil will always triumph, because good is dumb" - Dark Helmet[/blue]
 
Thanks Eric,

Simply putting Application.ProcessMessages on the procedure which increases the position of the ProgressBar solved my problem.

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top