Recent

Author Topic: How to know when dragging actually occurs when using BeginDrag(False)?  (Read 807 times)

Aistis

  • New Member
  • *
  • Posts: 18
    • Titbits of mind leakage
Today I was playing around with drag and drop controls for the first time. But I now have a question. Is there a way to know when a control is actually being dragged when using BeginDrag(False)?

For example, when I'm using BeginDrag(False, 5) (with DragMode := dmManual), a single stationary mouse press instantly calls the OnStartDrag and sets the TControl.Dragging to True despite my mouse position never breaking that 5 pixel threshold at which the dragging logic actually kicks in.

With the procedure signature being BeginDrag(Immediate: boolean; Threshold: integer) I naturally assumed that TControl.Dragging would be set to True only after exceeding the Threshold with the OnStartDrag event being called alongside it.

Is this the way it is supposed to work?

Edit: forgot to mention that I'm on Linux Mint. Haven't tested this on Windows yet.
« Last Edit: December 06, 2024, 08:35:18 am by Aistis »

jamie

  • Hero Member
  • *****
  • Posts: 6791
Re: How to know when dragging actually occurs when using BeginDrag(False)?
« Reply #1 on: December 06, 2024, 02:30:22 am »
I don't have Delphi in front of me atm, however, I Think this could be a bug because it makes no sense.

Reading online docs from the other guy leads me to believe that this should only report dragging as true when the threshold is reached.

Jamie the mad man!

The only true wisdom is knowing you know nothing

Aistis

  • New Member
  • *
  • Posts: 18
    • Titbits of mind leakage
Re: How to know when dragging actually occurs when using BeginDrag(False)?
« Reply #2 on: December 06, 2024, 08:56:21 pm »
Can't believe it took me this long to make a simple working example O:-)

With DragMode := dmManual set, OnStartDrag() starts the moment the control is clicked and not yet dragged despite having a BeginDrag(False, 5) in the control's OnMouseDown() event. Seeing how the BeginDrag signature is BeginDrag(Immediate: boolean; Threshold: integer) I assumed that the dragging should start after the threshold is hit (and so should OnStartDrag() be called after the threshold is hit).

Is there a way to know when the dragging actually occurs after escaping the threshold given to BeginDrag(False, 5)? I'm attaching the demo project and a GIF.
« Last Edit: December 06, 2024, 08:57:52 pm by Aistis »

Aistis

  • New Member
  • *
  • Posts: 18
    • Titbits of mind leakage
Re: How to know when dragging actually occurs when using BeginDrag(False)?
« Reply #3 on: December 09, 2024, 10:41:22 am »
Changing the ElemOnMouseDown from my attached project above and adding two new events makes it easy to get the behaviour that I want/expect (code bellow). But this kind of makes the whole BeginDrag(False, 5) moot, since I instead have to call BeginDrag(True) once I make sure the 5 pixel threshold is hit.

I'm attaching the demo project with these changes.

Code: Pascal  [Select][+][-]
  1. procedure TTest.ElemOnMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,
  2.   Y: Integer);
  3. begin
  4.   FStartingPoint := Point(X, Y);
  5.   FTrigger.OnMouseMove := @ElemOnMouseMove;
  6.   FTrigger.OnMouseUp := @ElemOnMouseUp;
  7. end;
  8.  
  9. procedure TTest.ElemOnMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,
  10.   Y: Integer);
  11. begin
  12.   FTrigger.OnMouseMove := nil;  
  13.   FTrigger.OnMouseUp := nil;
  14. end;
  15.  
  16. procedure TTest.ElemOnMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  17. begin
  18.   if FStartingPoint.Distance(Point(X, Y)) >= 5 then
  19.   begin
  20.     FTrigger.OnMouseMove := nil;    
  21.     FTrigger.OnMouseUp := nil;
  22.     FTrigger.BeginDrag(True);
  23.   end;
  24. end;

TControl.BeginDrag docs also mention how the set threshold is "Minimum mouse movement before delayed dragging starts". But as I said before, both OnStartDrag is called and Dragging is set to True when the TControl is pressed, not when the dragging actually starts when using BeginDrag(False).

Unless the word delayed in the docs means that the drag does starts from a mouse press but the process of dragging itself is delayed. But then again, that makes OnStartDrag() and Dragging; basically useless when using BeginDrag(False);.
« Last Edit: December 09, 2024, 10:45:15 am by Aistis »

 

TinyPortal © 2005-2018