Recent

Author Topic: [Solved] Custom component with drag-drop: issue on Windows  (Read 3412 times)

AlexTP

  • Hero Member
  • *****
  • Posts: 1766
    • UVviewsoft
[Solved] Custom component with drag-drop: issue on Windows
« on: December 20, 2021, 08:24:23 am »
Can somebody please tell me what am I doing wrong?
https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39515

This is affecting my main app.
« Last Edit: December 20, 2021, 11:54:13 am by Alextp »

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 762
Re: My custom component with drag-drop: issue on Windows
« Reply #1 on: December 20, 2021, 10:58:45 am »
First of all you need this:
Code: Pascal  [Select][+][-]
  1. procedure TMyPanel.DragOver(Sender, Source: TObject;X,Y: Integer; State: TDragState; var Accept: Boolean);
  2. begin
  3.   Accept := True;
  4. end;  
  5.  
  6. constructor TMyPanel.Create(TheOwner: TComponent);
  7. begin
  8.   inherited Create(TheOwner);
  9.   FMouseDownPnt:= Point(-1, -1);
  10.   Cursor:= crIBeam;
  11.   OnDragOver := @DragOver;
  12. end;  
  13.  
Second - you need to do this:
Code: Pascal  [Select][+][-]
  1. procedure TMyPanel.UpdateCursor;
  2. begin
  3.   if Mouse.IsDragging then
  4.   begin
  5.     if ssCtrl in GetKeyShiftState then
  6.       DragCursor:= crMultiDrag
  7.     else
  8.       DragCursor:= crDrag;
  9.   end;
  10. end;
  11.  
Please note, that cursor actually changes only after mouse movement. I'm not sure, if it's correct way to do things. Something is still wrong, because cursor flickers. I guess, you mix some "auto" and "manual" drag and drop functionality.

« Last Edit: December 20, 2021, 11:14:00 am by Mr.Madguy »
29.12.2021 - migration to DynamicData 4.1 is completed - complete overhaul of data access driver.
My project still requires full Delphi 2009 support to be ported to Lazarus.
It's time to finally do it, because Delphi 2009 is 13 years old.

AlexTP

  • Hero Member
  • *****
  • Posts: 1766
    • UVviewsoft
Re: My custom component with drag-drop: issue on Windows
« Reply #2 on: December 20, 2021, 11:53:52 am »
You are cool!
Thanks for the hint, I just added overloaded DragOver() method.
And 'DragCursor:=...'. Solved!

 

TinyPortal © 2005-2018