Skip to content

Instantly share code, notes, and snippets.

@SimaWB
Created February 19, 2019 07:10
Show Gist options
  • Save SimaWB/bfb1249bf74434f082148453c0019d1c to your computer and use it in GitHub Desktop.
Save SimaWB/bfb1249bf74434f082148453c0019d1c to your computer and use it in GitHub Desktop.
temporarily changes the cursor
unit uCursor;
interface
uses Controls, Forms;
type
TTmpCursor = class(TInterfacedObject, IInterface)
private
FCursor: TCursor;
public
constructor Create(const ACursor: TCursor);
destructor Destroy; override;
class function SetCursor(const ACursor: TCursor = crHourGlass): IInterface;
end;
implementation
{ TTmpCursor }
constructor TTmpCursor.Create(const ACursor: TCursor);
begin
inherited Create();
FCursor := Screen.Cursor;
Screen.Cursor := ACursor;
end;
destructor TTmpCursor.Destroy;
begin
if Assigned(Screen) then
Screen.Cursor := FCursor;
inherited Destroy();
end;
class function TTmpCursor.SetCursor(const ACursor: TCursor): IInterface;
begin
Result := TTmpCursor.Create(ACursor);
end;
end.
@SimaWB
Copy link
Author

SimaWB commented Feb 19, 2019

Usage;

procedure TForm1.Button1Click(Sender: TObject);  
begin  
  TTmpCursor.SetCursor();  
  // Do something  
end;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment