Skip to content

Instantly share code, notes, and snippets.

@tdelphi
Created September 16, 2015 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tdelphi/8af75d167229f47a227a to your computer and use it in GitHub Desktop.
Save tdelphi/8af75d167229f47a227a to your computer and use it in GitHub Desktop.
#delphi helper class to work with cursor
//MMWIN:CLASSCOPY
unit uLazyCursorHelper;
interface
uses
Controls;
type
/// <summary>
/// Changes screen cursor when method Change is called. And automatically restores it back.
/// </summary>
/// <remarks>
/// F.e.: TLazyCursorHelper.Change(crHourGlass);
/// </remarks>
TLazyCursorHelper = class(TInterfacedObject, IUnknown)
strict private
FOldCursor: TCursor;<><>
public
class function Change(const aNewCursor: TCursor): IUnknown;
class function ChangeToHourglass: IUnknown;
class function ChangeToSqlWait: IUnknown;
destructor Destroy; override;
end;
implementation
uses
Forms;
class function TLazyCursorHelper.ChangeToHourglass: IUnknown;
begin
result := Change(crHourGlass);
end;
class function TLazyCursorHelper.ChangeToSqlWait: IUnknown;
begin
result := Change(crSQLWait);
end;
destructor TLazyCursorHelper.Destroy;
begin
Screen.Cursor := FOldCursor;
inherited;
end;
class function TLazyCursorHelper.Change(const aNewCursor: TCursor): IUnknown;
var
tmpInstance: TLazyCursorHelper;
begin
tmpInstance := TLazyCursorHelper.Create;
tmpInstance.FOldCursor := Screen.Cursor;
Result := tmpInstance;
Screen.Cursor := aNewCursor;
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment