Recent

Author Topic: onDblClick on TMemo and TEdit glitch.  (Read 3777 times)

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • Burdjia
onDblClick on TMemo and TEdit glitch.
« on: September 30, 2014, 02:57:23 pm »
So, I have a TMemo, and I created an onDblClick event for it.  The event opens a modal dialog.  Problem is that when the modal dialog closes, the TMemo still tracks the mouse as it was selecting text.  That's quite annoying.  I wonder if I'm missing something or there's a workaround.

To reproduce the problem, just create a new project, add a TMemo to the form and set its double click event to this:
Code: [Select]
PROCEDURE TForm1.Memo1DblClick (Sender: TObject);
BEGIN
  MessageDlg ('Info', 'This will be weird!', mtInformation, [mbIgnore], 0)
END;
Now, if you doubleclick the memo, you'll see the message dialog, and after closing move the mouse over the memo without clicking.  You'll see you're selecting the text!

The glitch works on Linux + GTK (Fedora).
« Last Edit: September 30, 2014, 02:59:36 pm by Ñuño_Martínez »
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: onDblClick on TMemo and TEdit glitch.
« Reply #1 on: September 30, 2014, 04:27:03 pm »
Which Lazarus version?
If it happens in trunk, please open a ticket in the bugtracker (and attach a compilable project).

Bart

derek.john.evans

  • Guest
Re: onDblClick on TMemo and TEdit glitch.
« Reply #2 on: September 30, 2014, 05:58:11 pm »
Here is a workaround that will leave the cursor under the double clicked point. It stores the SelStart in OnClick, and then restores it if there is a DblClick.


Code: Pascal  [Select][+][-]
  1. procedure TFormMain.MemoClick(Sender: TObject);
  2. begin
  3.   FSelStart := Memo.SelStart;
  4. end;
  5.  
  6. procedure TFormMain.MemoDblClick(Sender: TObject);
  7. begin
  8.   Memo.SelStart := FSelStart;
  9.   ShowMessage('Double Click');
  10. end;        
  11.  
« Last Edit: October 02, 2015, 03:42:11 am by Geepster »

derek.john.evans

  • Guest
Re: onDblClick on TMemo and TEdit glitch.
« Reply #3 on: September 30, 2014, 06:06:00 pm »
Sorry for the double post. Another idea: Keep a copy of the current selection via a OnMouseMove, then you can restore the actual selection before a double click. There may be some side effects.

Code: Pascal  [Select][+][-]
  1. procedure TFormMain.MemoDblClick(Sender: TObject);
  2. begin
  3.   Memo.SelStart := FSelStart;
  4.   Memo.SelLength := FSelLength;
  5.   ShowMessage('Double Click');
  6. end;
  7.  
  8. procedure TFormMain.MemoMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  9. begin
  10.   FSelStart := Memo.SelStart;
  11.   FSelLength := Memo.SelLength;
  12. end;  
  13.  
« Last Edit: October 02, 2015, 03:41:55 am by Geepster »

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • Burdjia
Re: onDblClick on TMemo and TEdit glitch.
« Reply #4 on: October 01, 2014, 09:21:29 am »
Which Lazarus version?
The one that came with Fedora 20 - Lazarus 1.0.8 

Here is a workaround that will leave the cursor under the double clicked point. It stores the SelStart in OnClick, and then restores it if there is a DblClick.
It doesn't work.  The problem is that the control "thinks" that user is still pressing the mouse button.
« Last Edit: October 01, 2014, 09:27:25 am by Ñuño_Martínez »
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

rumen-lazarus

  • Newbie
  • Posts: 3
Re: onDblClick on TMemo and TEdit glitch.
« Reply #5 on: October 01, 2014, 03:23:23 pm »
My workaround is:

Code: [Select]
procedure TFormMain.MemoDblClick(Sender: TObject);
begin
  Application.QueueAsyncCall( acMemoDblClick,PtrInt(Sender));
end;

This is not ideal, but ...

 

TinyPortal © 2005-2018