views:

295

answers:

2

I am simply opening my FindDialog with:

FindDialog.Execute;

In my FindDialog.OnFind event, I want to change the cursor to an hourglass for searches through large files, which may take a few seconds. So in the OnFind event I do this:

Screen.Cursor := crHourglass;
(code that searches for the text and displays it) ...
Screen.Cursor := crDefault;

What happens is while searching for the text, the cursor properly changes to the hourglass (or rotating circle in Vista) and then back to the pointer when the search is completed.

However, this only happens on the main form. It does not happen on the FindDialog itself. The default cursor remains on the FindDialog during the search. While the search is happening if I move the cursor over the FindDialog it changes to the default, and if I move it off and over the main form it becomes the hourglass.

This does not seem like what is supposed to happen. Am I doing something wrong or does something special need to be done to get the cursor to be the hourglass on all forms?

For reference, I'm using Delphi 2009.

A: 

Try adding Application.ProcessMessages; after you set the cursor.

If this works, be sure to call your Mother, help an old lady cross the street, or maybe plant a tree. Otherwise, the devil will own another little piece of your soul.

Chris Thornton
@Chris. I do have Application.ProcessMessages in my search for text code but I didn't show it in my example above. If I didn't have it, then the cursor wouldn't have changed to the hourglass for the main form either.
lkessler
+1  A: 
Sertac Akyuz
@Sertac: That "almost" works. It seems that the HourGlass appears over some parts of the Find Dialog, but not all of it. Very strange! Anything that looks its an object placed on the dialog (e.g. a label, a button, an edit box) does not get the Hourglass appearing, but the form behind it does.
lkessler
Well, I guess that changes the cursor only for the dialog's "Form" and not for it's controls and that you need to set all the child windows' cursor too. I think EnumChildWindows will do the job.
Ken Bourassa
Edited to propose an alternative to enumarating controls on the dialog. I don't know if it's less code or if it's more proper though...
Sertac Akyuz
@Sertac: This is better. The hourglass now comes on the FindDialog and its controls. However, when the find is completed, the cursor over the controls of the FindDialog are set back to default, but the cursor over the parts of the FindDialog without a control over it still have the hourglass. Also, I now notice (didn't before) that a few controls on my main form do not change to hourglass. Maybe windows standards want the hourglass handled this way and I shouldn't be fooling around with it(???).
lkessler
@Ikessler - (1) Confirmed, added a call to SetCursor after resetting the window procedure... (2) - I dunno, I have no knowledge of an HourGlass cursor usage design guide <g>. Is it possible to duplicate with standard VCL controls?
Sertac Akyuz
@Sertac: Unfortunately neither the SetCursor line nor the SendMessage line you commented out set the cursor over the FindDialog back to default. I think maybe Windows does something special with the cursor over controls, because you want to be able to press a control with a pointer even if something is running in the background.
lkessler
@lkessler - Weird.. seems to work here. Perhaps a "SetClassLong" leftover? ... I don't think the OS does anything with the cursor behind your back. It makes sense not to change it to HourGlass if indeed you can use the cursor in anyway. But, my view is, that should be a design consideration.
Sertac Akyuz
@Sertac: Thanks for letting me know it worked for you. I went back and found some code not done correctly that prevented the cursor from being set back. Now I've fixed that and it all works as you said. Thanks so much for your work to help me out here. Much appreciated. You get the accepted answer.
lkessler
@lkessler - Thanks, and you're welcome!
Sertac Akyuz