Created
September 16, 2015 11:02
-
-
Save tdelphi/8af75d167229f47a227a to your computer and use it in GitHub Desktop.
#delphi helper class to work with cursor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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