[Lazarus] screen.cursor := crHourglass and Linux

DSK pnewbieii at gmail.com
Mon Apr 18 20:21:53 CEST 2011


John,

>do i really need allways
>screen.cursor := crHouglass;
>followed by
>Application.Processmessages;

I have this bit of code I wanted to send but I wasn't going to post it 
without testing it [I've only ever run it on windows apps] on a Linux 
platform and I had some difficulties getting Lazarus on Ubuntu running - 
but that's another story. It's a bit of code I found ages ago and have 
refactored here and there. It makes dealing with changing to the HourGlass 
and back in any method much simpler to deal with ... at any rate here it is:

*****************************************************
unit CursorCtrl;

interface
uses
   Controls, Forms;

type
   ITemporaryCursor = interface
   ['{38BDD5A3-2E23-47D1-BD5D-54C49DBC95C3}']
     procedure Show;
   end;

   TTemporaryCursor = class(TInterfacedObject, ITemporaryCursor)
   private
     FOldCursor: TCursor;
     FNewCursor: TCursor;
   public
     constructor Create(const Cursor: TCursor = crHourglass);
     destructor Destroy; override;
     procedure Show;
   end;

function DisplayCursor(const Cursor: TCursor): ITemporaryCursor;
function DisplayHourglass: ITemporaryCursor;

implementation

{ TTemporaryCursor }
constructor TTemporaryCursor.Create(const Cursor: TCursor = crHourglass);
begin
   inherited Create();
   FOldCursor := Screen.Cursor;
   FNewCursor := Cursor;
end;

destructor TTemporaryCursor.Destroy;
begin
   Screen.Cursor := FOldCursor;
   inherited;
end;

procedure TTemporaryCursor.Show;
begin
   Screen.Cursor := FNewCursor;
   Application.ProcessMessages;
end;

{Use these routines to change a cursor before a long process in any method.}

function DisplayCursor(const Cursor: TCursor): ITemporaryCursor;
begin
   Result := TTemporaryCursor.Create(Cursor) as ITemporaryCursor;
   Result.Show;
end;

{- or -}

function DisplayHourglass: ITemporaryCursor;
begin
   Result := TTemporaryCursor.Create as ITemporaryCursor;
   Result.Show;
end;

end.

*********************************************************************
To use it, add the unit to the implementation uses clause and then just 
call DisplayHourglass before any long process. It'll switch back to 
whatever the cursor was then the method terminates.

Hope you find it of interest.
-- 
Dave
Posted with XanaNews 1.19.1.320





More information about the Lazarus mailing list