windows - Delphi 6 cursor not changing -


if have buttonclick event sets cursor := crhourglass, application.processmessages, use topendialog choose file, , cpu-intensive, cursor behaves differently depending on whether on existing control when open dialog closes. if cursor on control cursor remains hourglass; if it's outside application , moved area while intensive process still taking place, cursor remains arrow. 1 cannot click or it's confusing user arrow not able it.

stepping through debugger shows cursor -11 everywhere should be. using screen.cursor instead of cursor has same effect.

is there solution?

procedure tmyform.loadbuttonclick(sender: tobject); begin   cursor := crhourglass;   application.processmessages;   if opendialog.execute begin     // intensive     // cursor = crhourglass here displayed different   end;   cursor := crdefault; end; 

first, make sure set cursor while cpu-intensive operation active. don't change cursor while choosing file — never see other programs that, after all.

second, when cursor in code, you're referring form's property. might wish use screen.cursor instead entire program displays same cursor.

third, there's no need call application.processmessages. messages going processed display dialog box anyway, , besides, there no particular messages need processed.

finally, consider protecting cursor changes try-finally block problems in processing don't leave cursor in wrong state:

if opendialog.execute begin   screen.cursor := crhourglass;   try     // todo: intensive       screen.cursor := crdefault;   end; end; 

if operation uses lot of time, consider moving off thread. don't have worry gui being unresponsive, , won't have change cursor in first place.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -