How to load custom cursor in Firemonkey?


I need to use custom cursor in my Firemonkey desktop project. I can use LoadCursorFromFile in VCL project to load a custom cursor in my project. I have tried to do the same for Firemonkey but it is not loading the cursor. Is there any working way to achieve loading custom cursors in Firemonkey?

uses Winapi.Windows; procedure Tform1.Button1Click(Sender: TObject); const mycursor= 1; begin Screen.Cursors[mycursor] := LoadCursorFromFile('C:\...\Arrow.cur'); Button1.Cursor := mycursor; end;


I only did this for the Mac, but the general idea is that you implement your own IFMXCursorService. Keep in mind that this pretty much an all or nothing approach. You'll have to implement the default FMX cursors, too.

type TWinCursorService = class(TInterfacedObject, IFMXCursorService) private class var FWinCursorService: TWinCursorService; public class constructor Create; procedure SetCursor(const ACursor: TCursor); function GetCursor: TCursor; end; { TWinCursorService } class constructor TWinCursorService.Create; begin FWinCursorService := TWinCursorService.Create; TPlatformServices.Current.RemovePlatformService(IFMXCursorService); TPlatformServices.Current.AddPlatformService(IFMXCursorService, FWinCursorService); end; function TWinCursorService.GetCursor: TCursor; begin // to be implemented end; procedure TWinCursorService.SetCursor(const ACursor: TCursor); begin Windows.SetCursor(Cursors[ACursor]); // you need to manage the Cursors list that contains the handles for all cursors end;

It might be a necessary to add a flag to the TWinCursorService so that it will prevent the FMX framework to override your cursor.

Timing is important when registering your own cursor service. It will have to be done after FMX calls TPlatformServices.Current.AddPlatformService(IFMXCursorService, PlatformCocoa);


Unfortunately, FireMonkey does not support custom cursors. This has already been filed as a feature request in Quality Portal:

<a href="https://quality.embarcadero.com/browse/RSP-17651" rel="nofollow">RSP-17651 Cannot load custom cursors in Firemonkey</a>.

With that said, the code you showed would not work in VCL. <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms648392.aspx" rel="nofollow">LoadCursorFromFile()</a> returns an HCURSOR handle, but the TControl.Cursor property expects an index value from the TCursor enum instead. They are not the same thing. When loading a custom cursor, you must add it to the TScreen.Cursors[] list. This is clearly stated in the documentation:

<a href="http://docwiki.embarcadero.com/Libraries/XE7/en/Vcl.Controls.TControl.Cursor" rel="nofollow">Vcl.Controls.TControl.Cursor</a>


The value of Cursor is the <strong>index of the cursor in the list of cursors maintained by the global variable, Screen</strong>. In addition to the built-in cursors provided by TScreen, <strong>applications can add custom cursors to the list</strong>.


<a href="http://docwiki.embarcadero.com/Libraries/XE7/en/Vcl.Forms.TScreen.Cursors" rel="nofollow">Vcl.Forms.TScreen.Cursors</a>


Custom cursors can be added to the Cursors property for use by the application or any of its controls. To add a custom cursor to an application, you can ...:<br /> ...<br /> 2. Declare a cursor constant with a value that does not conflict with an existing cursor constant.<br /> ...<br /> 4. Set the Cursors property, indexed by the newly declared cursor constant, to the handle obtained from LoadCursor.


For example:

const mycursor: TCursor = 1; // built-in values are <= 0, user-defined values are > 0 procedure Tform1.Button1Click(Sender: TObject); begin Screen.Cursors[mycursor] := LoadCursorFromFile('C:\...\Arrow.cur'); Button1.Cursor := mycursor; end;


  • Image link with $confirmMessage alert in Cakephp HTMLhelper - possible?
  • Fluent interface with inheritance in Delphi
  • Unknown type name with typedef struct in C
  • bootstrappedUser - Jade or EJS to HTML
  • Redmine can't generate secret token
  • Is it possible to add a hyperlink to a UIAlertController?
  • Facebook like button redirect? [closed]
  • Working with codeception and laravel
  • Target in barchart in dc.js
  • Can I switch the 'connected' user within an sql script that is sourced by mysql?
  • Anaconda + Apache + mod_wsgi + Ubuntu
  • How to show functions callback and errors on UI with bloc pattern in Flutter?
  • Enable CORS on Tomcat 8.0.30
  • Force outer SELECT to fail if the inner SELECT contains an invalid identifier
  • Implementing type equation generator in OCaml
  • How to escape xpath in php
  • Draw string with normalized scientific notation (superscripted )
  • Simultaneous animation when entering editing mode of UITableViewCell
  • Homomorphic filtering in OpenCV
  • Scheme procedure to compute the nth repeated application of a function?
  • Windows biometric framework sample umdf driver: This device cannot start. (Code 10)
  • Arraylist of strings into one comma separated string
  • Spotify cocoalibspotify offline status set to 1 but all tracks stuck at waiting
  • How to make Rss News Reader application in android …? [closed]
  • Floating parent div grows to hypothetical width of floating child div
  • Calculate time from document
  • jQuery scrollTop if URL has hash
  • Will this work on all screen sizes?
  • How to integrate angular2-material (alpha 8.2) with angular2-Quickstart app
  • read part of h5 dataset python
  • Send array to next viewcontroller iOs xcode [duplicate]
  • Computing the discrete fourier transform of audio data with FFTW
  • Codeigniniter insert data through models and controller
  • PHP Permalinks.. how to change?
  • Write to .csv file with PHP (Commas in Data Error)
  • Spring Boot not autowiring @Repository
  • What does the “id” field in an Android “Google Play Music” broadcast intent correspond to?
  • ARKit code issue {unknown error -1=ffffffffffffffff error: Task failed with exit 1}