Recent

Author Topic: Wait Cursor / Hourglass  (Read 12206 times)

Astral

  • New Member
  • *
  • Posts: 49
Wait Cursor / Hourglass
« on: June 28, 2009, 03:55:02 am »
I'm wondering if I can find a replacement for my unit
WCursor.pas

This little unit was written by someone else and worked fine on Delphi.

I basically need to display an hourglass cursor and a normal cursor,
with calls like:

WCursor.SetWait;

and

WCursor.Normal;


This is the code I am using on Delphi:

Code: [Select]
unit WCursor;
{ WaitCursor  -  Copyright (c) 2001 by E.J.Molendijk

  A mousecursor hourglass/normal changer tool. Supports layered requests.

  WCursor.SetWait     = mouse cursor as Hourglass
  WCursor.SetWaitSQL  = mouse cursor as SQL Hourglass
  WCursor.SetNormal   = mouse cursor as normal

  example:
      WCursor.setWait;
      try
        DoSometingVerySlow;
      finally
        WCursor.setNormal;
      end;
}

interface

type
  TWaitCursor = class
  private
     FCursor : integer;
     FCnt : integer;
  public
     constructor Create;
     destructor  Destroy; override;
     procedure   SetCursor(Index: integer);
     procedure   SetWait;
     procedure   SetWaitSQL;
     procedure   SetNormal;
  end;

var
  WCursor : TWaitCursor;

implementation

uses Forms, Controls;

constructor TWaitCursor.Create;
begin
  inherited;
  // depth is zero
  FCnt := 0;

  // remember default cursor
  FCursor := Screen.Cursor;
end;

destructor TWaitCursor.Destroy;
begin
  // Reset to default cursor
  Screen.Cursor := FCursor;
  inherited;
end;

procedure TWaitCursor.SetCursor(Index: integer);
begin
  // select cursor
  Screen.Cursor := Index;
end;

procedure TWaitCursor.SetNormal;
begin
  // decrease depth
  if FCnt>0 then Dec(FCnt);

  // if we reach depth 0 we restore default cursor
  if FCnt=0 then SetCursor(FCursor);
end;

procedure TWaitCursor.SetWait;
begin
  // increase depth
  Inc(FCnt);

  // select wait cursor
  SetCursor(crHourglass);
end;

procedure TWaitCursor.SetWaitSQL;
begin
  // increase depth
  Inc(FCnt);

  // select wait cursor
  SetCursor(crSQLWait);
end;

initialization
  WCursor := TWaitCursor.Create;
finalization
  WCursor.Free;
end.


Astral

  • New Member
  • *
  • Posts: 49
Re: Wait Cursor / Hourglass
« Reply #1 on: June 28, 2009, 04:08:15 am »
Gosh, I always manage to figure it out right AFTER posting a question.

I renamed the unit to WaitCursor.pas instead of WCursor.pas and then I was able to refer to WCursor.SetWait.  When the unit was named the same as a variable inside, it apparently got confused.

I don't think I had this problem on Delphi, or maybe I did and solved it in the same way, but the evidence I have shows otherwise.

I just ran a test and the hourglass cursor is working.

I don't understand the code exactly, but that's the beauty of it, you don't have to understand it to make it work.   ::)

 

TinyPortal © 2005-2018