Mega Code Archive

 
Categories / Delphi / System
 

A way to handle displaying screen cursors

Title: A way to handle displaying screen cursors Question: Do you have code like this? PrevCursor:= Screen.Cursor; Screen.Cursor:= crHourGlass; try finally Screen.Cursor:= PrevCursor; end; Thats annoying code to rewrite every time. Answer: Replace that code with: PushCursor(crHourGlass) try finally PopCursor; end; Here is the unit: =========================== unit CursorStack; { Author: William Egge, egge@eggcentric.com Screen cursor handling } interface uses Controls, Forms, Classes, SysUtils; procedure PushCursor(Cursor: TCursor); procedure PopCursor; implementation var FCursorList: TList = nil; procedure PushCursor(Cursor: TCursor); begin if FCursorList nil then begin FCursorList.Add(Pointer(Screen.Cursor)); Screen.Cursor:= Cursor; end; end; procedure PopCursor; begin if FCursorList nil then begin Screen.Cursor:= TCursor(FCursorList.Last); FCursorList.Delete(FCursorList.Count-1); end; end; initialization FCursorList:= TList.Create; finalization FreeAndNil(FCursorList); end.