Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-09

Changing the cursor to hourglass then to default

9 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Richard Mace

Hi,
I am trying to change the cursor in my app to busy and then default, when it is going to be busy for a bit.
I have changed to cursor := crHourglass and then back to crDefault at the end, but the cursor doesn't update.
Even if I put application.processmessages in (after the crHourglass bit).

Any ideas?

Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130920/d6d0c4f0/attachment-0001.html>

Reply by email

Antonio Fortuny
to Richard Mace

Le 20/09/2013 15:47, Richard Mace a ?crit :

Show quoted text 5 lines
Hi, I am trying to change the cursor in my app to busy and then default, when it is going to be busy for a bit. I have changed to cursor := crHourglass and then back to crDefault at the end, but the cursor doesn't update.
*Screen.*Cursor := crHourGlass;
try
   ...
finally
*Screen.*Cursor := crDefault;
end;

works fine for me in all platforms.

Antonio.

Show quoted text 12 lines
Even if I put application.processmessages in (after the crHourglass bit). Any ideas? Richard -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130920/cd4025b1/attachment.html>

Reply by email

Graeme Geldenhuys
to Antonio Fortuny
Antonio Fortuny wrote 6 lines
*Screen.*Cursor := crHourGlass; try ... finally *Screen.*Cursor := crDefault; end;

Another trick - slightly better that yours [I think] - is to use interfaces instead. That way you can nest cursor changes, and know the interfaces will unwind the correct previous cursor for you, be it clHourGlass, clSQLWait, clDefault etc.

----8<-------------8<-------------8<-------------8<-------------8<----
unit CodeToolbox;
interface
function tiAutoCursor(ACursor: TCursor = crHourglass): IUnknown;
function tiAutoWaitCursor: IUnknown;
implementation
type
  TtiAutoCursor = class(TInterfacedObject)
  private
  public
    constructor Create(ANewCursor: TCursor);
    destructor Destroy; override;
  end;
var
  uCursorStack: TList;
function tiCursorStack: TList;
begin
  if not Assigned(uCursorStack) then
    uCursorStack := TList.Create;
  Result := uCursorStack;
end;
constructor TtiAutoCursor.Create(ANewCursor: TCursor);
begin
  inherited Create;
  // push
  tiCursorStack.Add(@(Screen.Cursor));
  Screen.Cursor := ANewCursor;
end;
destructor TtiAutoCursor.Destroy;
begin
  // pop
  Screen.Cursor := TCursor(tiCursorStack.Last);
  tiCursorStack.Delete(uCursorStack.Count-1);
  inherited;
end;
function tiAutoCursor(ACursor: TCursor = crHourglass): IUnknown;
begin
  if GetCurrentThreadId = MainThreadId then
    Result := TtiAutoCursor.Create(ACursor);
end;
function tiAutoWaitCursor: IUnknown;
begin
  if GetCurrentThreadId = MainThreadId then
    Result := TtiAutoCursor.Create(crHourglass)
  else
    Result := nil;
end;
initialization
finalization
  FreeAndNil(uCursorStack);

----8<-------------8<-------------8<-------------8<-------------8<----

You can now use the above code as follows.

procedure Foo;
var
  ms: IUnknown;  // FPC requires this, Delphi doesn't.
begin
  ms := tiAutoCursor;
  // do something long
  // Note: No need to reset the cursor. The Interface will do
  //       that automatically when it goes out of scope.
end;

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

Martin
to Richard Mace: I am trying to change the cursor in my app to busy and then default, when it is going to…
Richard Mace wrote 6 lines
Hi, I am trying to change the cursor in my app to busy and then default, when it is going to be busy for a bit. I have changed to cursor := crHourglass and then back to crDefault at the end, but the cursor doesn't update. Even if I put application.processmessages in (after the crHourglass bit).

On some platforms there is an issue, and the cursor image only updates if the mouse moves
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130920/ca783b7e/attachment.html>

Reply by email

Antonio Fortuny
to Martin

Le 20/09/2013 16:52, Martin a ?crit :

Show quoted text 10 lines
On 20/09/2013 14:47, Richard Mace wrote: > Hi, > I am trying to change the cursor in my app to busy and then default, > when it is going to be busy for a bit. > I have changed to cursor := crHourglass and then back to crDefault at > the end, but the cursor doesn't update. > Even if I put application.processmessages in (after the crHourglass bit). On some platforms there is an issue, and the cursor image only updates if the mouse moves

Yep: WinCE on handheld computers but in a random manner !

Antonio;
Show quoted text 7 lines
-- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Sita Software *Antonio Fortuny* Senior Software engineer 220, avenue de la Libert? L-4602 Niederkorn Tel.: +352 58 00 93 - 93 www.sitasoftware.lu <http://www.sitasoftware.lu> Your IT Partner -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130920/ab7a8b0c/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: idgghgjj.jpg Type: image/jpeg Size: 2306 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130920/ab7a8b0c/attachment-0002.jpg> -------------- next part -------------- A non-text attachment was scrubbed... Name: hggjccii.jpg Type: image/jpeg Size: 921 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130920/ab7a8b0c/attachment-0003.jpg>

Reply by email

Richard Mace
to Antonio Fortuny: Le 20/09/2013 15:47, Richard Mace a ?crit : *Screen.*Cursor := crHourGlass; try ...…

Le 20/09/2013 15:47, Richard Mace a ?crit :

Show quoted text 17 lines
Hi, I am trying to change the cursor in my app to busy and then default, when it is going to be busy for a bit. I have changed to cursor := crHourglass and then back to crDefault at the end, but the cursor doesn't update. *Screen.*Cursor := crHourGlass; try ... finally *Screen.*Cursor := crDefault; end; works fine for me in all platforms. Antonio.

Perfect. Worked a treat.

Thanks

Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130920/b3e96b66/attachment.html>

Reply by email

Sven Barth
to Graeme Geldenhuys: Another trick - slightly better that yours [I think] - is to use interfaces instead. That…
"Graeme Geldenhuys" wrote 99 lines
On 2013-09-20 15:03, Antonio Fortuny wrote: > *Screen.*Cursor := crHourGlass; > try > ... > finally > *Screen.*Cursor := crDefault; > end; Another trick - slightly better that yours [I think] - is to use interfaces instead. That way you can nest cursor changes, and know the interfaces will unwind the correct previous cursor for you, be it clHourGlass, clSQLWait, clDefault etc. ----8<-------------8<-------------8<-------------8<-------------8<---- unit CodeToolbox; interface function tiAutoCursor(ACursor: TCursor = crHourglass): IUnknown; function tiAutoWaitCursor: IUnknown; implementation type TtiAutoCursor = class(TInterfacedObject) private public constructor Create(ANewCursor: TCursor); destructor Destroy; override; end; var uCursorStack: TList; function tiCursorStack: TList; begin if not Assigned(uCursorStack) then uCursorStack := TList.Create; Result := uCursorStack; end; constructor TtiAutoCursor.Create(ANewCursor: TCursor); begin inherited Create; // push tiCursorStack.Add(@(Screen.Cursor)); Screen.Cursor := ANewCursor; end; destructor TtiAutoCursor.Destroy; begin // pop Screen.Cursor := TCursor(tiCursorStack.Last); tiCursorStack.Delete(uCursorStack.Count-1); inherited; end; function tiAutoCursor(ACursor: TCursor = crHourglass): IUnknown; begin if GetCurrentThreadId = MainThreadId then Result := TtiAutoCursor.Create(ACursor); end; function tiAutoWaitCursor: IUnknown; begin if GetCurrentThreadId = MainThreadId then Result := TtiAutoCursor.Create(crHourglass) else Result := nil; end; initialization finalization FreeAndNil(uCursorStack); ----8<-------------8<-------------8<-------------8<-------------8<---- You can now use the above code as follows. procedure Foo; var ms: IUnknown; // FPC requires this, Delphi doesn't. begin ms := tiAutoCursor; // do something long // Note: No need to reset the cursor. The Interface will do // that automatically when it goes out of scope. end;

Weren't you the one who asked some years ago why FPC behaves differently on that case? Because the time when an interface's reference count is decreased is an implementation detail...

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130921/b3147c65/attachment.html>

Reply by email

Graeme Geldenhuys
Sven Barth wrote
Weren't you the one who asked some years ago why FPC behaves differently on that case?

[please consider trimming some quotes before you post]

Yes I mentioned the annoyance and difference regarding Delphi, but apparently "Delphi incompatible" is sometimes accepted. Strange but true. ;-)

Regards,
Graeme.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130921/2bbaeb00/attachment.html>

Reply by email

Sven Barth
to Graeme Geldenhuys
Graeme Geldenhuys wrote
On Saturday 21/09/2013 at 18:40, Sven Barth wrote: > Weren't you the one who asked some years ago why FPC behaves > differently on that case? [please consider trimming some quotes before you post]

Not when I'm on a train with only my mobile and being tired as hell...

Regards,
Sven

Reply by email