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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cancelling a loop 1

Status
Not open for further replies.

DrRodge

Programmer
Jun 19, 2004
1
GB
I am writing a Delphi app which loops through a list of computer generated words and checking they exist using the WordApp component. This can take some time and I have added a cancel button to break the loop. Of course, the button OnClick message never gets through so I tried running the word checking loop on a separate thread. Normally, this would work but I get an EOleException saying 'CoInitialize has not been called'.

I can find no reference to CoInitialize so I am stuck. If anyone knows how to get round this problem, or has a different idea of how to brek out of the loop by clicking on a button, please let me know. Cheers.
 
Include the line
Code:
Application.ProcessMessages;
inside the loop. Then when the user clicks a button you can set a variable to indicate that cancel has been requested. Finish it up with
Code:
if bCancelRequested then Break;
I usually put up a message box to confirm that the user really wants to cancel and then Break only if he says Yes.
 
Hi.
Include the ActiveX unit, then call CoInitialize

//Nordlund
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top