In Delphi 6, I can change the mouse cursor for all forms using Screen.Cursor :
procedure TForm1.Button1Click(Sender: TObject); begin Screen.Cursor := crHourglass; end;
I am looking for the equivalent in Firemonkey.
The following function does not work:
procedure SetCursor(ACursor: TCursor); var CS: IFMXCursorService; begin if TPlatformServices.Current.SupportsPlatformService(IFMXCursorService) then begin CS := TPlatformServices.Current.GetPlatformService(IFMXCursorService) as IFMXCursorService; end; if Assigned(CS) then begin CS.SetCursor(ACursor); end; end;
When I insert Sleep(2000); At the end of the procedure, I see the cursor for 2 seconds. But the interface is probably freed, and therefore the cursor is automatically set at the end of the procedure. I also tried to define CS as a global variable and add CS._AddRef at the end of the procedure to prevent the interface from freeing up. But that didn't help either.
The following code works, but will only work for the main form:
procedure TForm1.Button1Click(Sender: TObject); begin Application.MainForm.Cursor := crHourGlass; end;
Since I want to change the cursor for all forms, I will need to iterate over all forms, but rolling back to previous cursors is difficult, since I need to know the previous cursor for each form.
My intention:
procedure TForm1.Button1Click(Sender: TObject); var prevCursor: TCursor; begin prevCursor := GetCursor; SetCursor(crHourglass); // for all forms try Work; finally SetCursor(prevCursor); end; end;
source share