Author: Erwin Molendijk How to change the mousecursor into a hourglass/normal. Answer: 1 unit waitcursor; 2 { WaitCursor - Copyright (c) 2001 by E.J.Molendijk 3 4 A mousecursor hourglass/normal changer tool. Supports layered requests. 5 6 WCursor.SetWait = mouse cursor as Hourglass 7 WCursor.SetWaitSQL = mouse cursor as SQL Hourglass 8 WCursor.SetNormal = mouse cursor as normal 9 10 example: 11 WCursor.setWait; 12 try 13 DoSometingVerySlow; 14 finally 15 WCursor.setNormal; 16 end; 17 } 18 19 interface 20 21 type 22 TWaitCursor = class 23 private 24 FCursor: integer; 25 FCnt: integer; 26 public 27 constructor Create; 28 destructor Destroy; override; 29 procedure SetCursor(Index: integer); 30 procedure SetWait; 31 procedure SetWaitSQL; 32 procedure SetNormal; 33 end; 34 35 var 36 WCursor: TWaitCursor; 37 38 implementation 39 40 uses Forms, Controls; 41 42 constructor TWaitCursor.Create; 43 begin 44 inherited; 45 // depth is zero 46 FCnt := 0; 47 48 // remember default cursor 49 FCursor := Screen.Cursor; 50 end; 51 52 destructor TWaitCursor.Destroy; 53 begin 54 // Reset to default cursor 55 Screen.Cursor := FCursor; 56 inherited; 57 end; 58 59 procedure TWaitCursor.SetCursor(Index: integer); 60 begin 61 // select cursor 62 Screen.Cursor := Index; 63 end; 64 65 procedure TWaitCursor.SetNormal; 66 begin 67 // decrease depth 68 if FCnt > 0 then 69 Dec(FCnt); 70 71 // if we reach depth 0 we restore default cursor 72 if FCnt = 0 then 73 SetCursor(FCursor); 74 end; 75 76 procedure TWaitCursor.SetWait; 77 begin 78 // increase depth 79 Inc(FCnt); 80 81 // select wait cursor 82 SetCursor(crHourglass); 83 end; 84 85 procedure TWaitCursor.SetWaitSQL; 86 begin 87 // increase depth 88 Inc(FCnt); 89 90 // select wait cursor 91 SetCursor(crSQLWait); 92 end; 93 94 initialization 95 WCursor := TWaitCursor.Create; 96 finalization 97 WCursor.Free; 98 end.