Autor Beitrag
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Do 04.07.02 07:55 
First (because many fall into this trap at first), make sure the .RES you're storing your cursor in is not named the same as your project, ie; if your project is MyApp.DPR then do not add resources to MyApp.RES. You must create a separately named .RES (eg; MyApp01.RES) and include it, eg;
ausblenden Delphi-Quelltext
1:
2:
3:
implementation

{$R MyApp01.Res}

You cannot assign a cursor directly from the .RES to a component's Cursor or DragCursor properties, you need to add a step in between. In every project, Delphi defines a global object called Screen (of type TScreen) which, among other things, defines an array of cursors called (strangely enough) Cursors. When you click on a Cursor/DragCursor property in the Object Inspector, it lets you drop down a list of the predefined cursors - this is where this list is coming from.

Delphi uses the array values starting at -1 and works down (ie; all negative) for the pre-defined cursors, which means you can use the values beginning at 0 and work up.

So, define a constant, eg:
ausblenden Delphi-Quelltext
1:
2:
Const
  MyCursor = 1;

Then in the form's OnCreate event, load the cursor:
ausblenden Delphi-Quelltext
1:
Screen.Cursors[MyCursor] := LoadCursor(HInstance, 'MYCURSOR');					


Then, just simply set the DragCursor property of any control:
ausblenden Delphi-Quelltext
1:
MyListbox.DragCursor := MyCursor;					

Note: the name of your cursor must be in UPPERCASE both in LoadCursor call above and as named in your .RES file.

Der Autor dieser FAQ ist mir leider nicht bekannt. Tino