type ICursorSaver = interface end; TCursorSaver = class(TInterfacedObject, ICursorSaver) private FCursor: TCursor; public constructor Create; destructor Destroy; override; end; implementation constructor TCursorSaver.Create; begin FCursor := Screen.Cursor; end; destructor TCursorSaver.Destroy; begin Screen.Cursor := FCursor; inherited; end;
ICursorSaver
and initialize it.
var saveCursor: ICursorSaver; begin saveCursor := TCursorSaver.Create; Screen.Cursor := crSQLWait; // , end;
TInterfacedObject
keeps track of references to the interface, when the counter drops to zero - the destructor is called. At the beginning of the scope, we create an object and initialize the interface variable to it, and the current view of the cursor is captured. At the end of the scope, the interface variable is destroyed, the interface is released, the destructor returns the cursor to its original state.
constructor TCursorSaver.Create(ACursor: TCursor = crHourGlass); begin FCursor := Screen.Cursor; Screen.Cursor := ACursor; end;
Source: https://habr.com/ru/post/147575/