Recent

Author Topic: How to capture the OnDrop event on TMemo.  (Read 632 times)

tomitomy

  • Full Member
  • ***
  • Posts: 241
How to capture the OnDrop event on TMemo.
« on: April 10, 2021, 04:58:26 am »
Hello everybody, I have a question, can someone help me?

I want capture the OnDrop event when I drop some text form other application(or other controls) into TMemo, but I don't know how, is there a way to do this?

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 511
  • Professional amateur ;-P
Re: How to capture the OnDrop event on TMemo.
« Reply #1 on: April 10, 2021, 05:07:57 am »
Hey tomitomy,

I want capture the OnDrop event when I drop some text form other application(or other controls) into TMemo, but I don't know how, is there a way to do this?

When you say "when I drop some text", do you mean Paste some text?

Cuz that would trigger the OnChange if I'm not mistaken.

Cheers,
Gus
Lazarus 2.1.0(trunk) FPC 3.3.1(trunk) Ubuntu 20.10 64b Dark Theme
Lazarus 2.0.12(stable) FPC 3.2.0(stable) Ubuntu 20.10 64b Dark Theme
http://github.com/gcarreno

tomitomy

  • Full Member
  • ***
  • Posts: 241
Re: How to capture the OnDrop event on TMemo.
« Reply #2 on: April 10, 2021, 05:54:53 am »
When you say "when I drop some text", do you mean Paste some text?

Hi, Gus,

Thank you for you reply. Sorry for my poor English, I mean drag some text into TMemo, I want to distinguish OnChange and OnDrop events.

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 511
  • Professional amateur ;-P
Re: How to capture the OnDrop event on TMemo.
« Reply #3 on: April 10, 2021, 07:18:22 am »
Hey tomitomy,

Thank you for you reply. Sorry for my poor English,

Quite welcome.
The problem is not your English. It's rather good I find!!

I mean drag some text into TMemo, I want to distinguish OnChange and OnDrop events.

I still don't understand what you mean by "I mean drag some text into TMemo". That for me is some kind of Paste and will always trigger OnChange.

I had a goo look at TMemo's events, and the is no OnDrop. Do you mean OnDragDrop?

Cheers,
Gus
Lazarus 2.1.0(trunk) FPC 3.3.1(trunk) Ubuntu 20.10 64b Dark Theme
Lazarus 2.0.12(stable) FPC 3.2.0(stable) Ubuntu 20.10 64b Dark Theme
http://github.com/gcarreno

lucamar

  • Hero Member
  • *****
  • Posts: 3895
Re: How to capture the OnDrop event on TMemo.
« Reply #4 on: April 10, 2021, 07:45:35 am »
I guess he means, for example, selecting some text in another text editor, dragging and droping it on the memo.

AFAICT there is no event to capture it; you'll probably have to intercept whatever message is sent when that happens, which I don't remember ATM which it is (and probably depends on the paltform/widgetset), sorry :-[

I've never had to use something like this, the usual auto-pasting of the text in the memo works well for me, but I can see where it could come in handy, to differentiate between normal editing actions and a text-drop before an OnChange event.

I had a goo look at TMemo's events, and the is no OnDrop. Do you mean OnDragDrop?

That won't work in this context; all the drag-drop related events work only for dragging a control/object and dropping it over another, like one does e.g. in the form designer. 
« Last Edit: April 10, 2021, 07:49:17 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

tomitomy

  • Full Member
  • ***
  • Posts: 241
Re: How to capture the OnDrop event on TMemo.
« Reply #5 on: April 10, 2021, 07:49:28 am »
I still don't understand what you mean by "I mean drag some text into TMemo". That for me is some kind of Paste and will always trigger OnChange.

Hi Gus,

Thank you, my English is translated from Chinese by the translation website. Occasionally I will write some by myself, I hope it won't cause you trouble.

I'm rewriting the undoredo function to support "undo by word" rather than just "undo by character". I've finished it, but I want to improve efficiency, I need to distinguish between ordinary typing and user drag and drop operations, so as to provide faster algorithm for ordinary typing operations, but I can't distinguish them. So I post for help.

Cheers,
Tomi

tomitomy

  • Full Member
  • ***
  • Posts: 241
Re: How to capture the OnDrop event on TMemo.
« Reply #6 on: April 10, 2021, 07:56:21 am »
I guess he means, for example, selecting some text in another text editor, dragging and droping it on the memo.

AFAICT there is no event to capture it; you'll probably have to intercept whatever message is sent when that happens, which I don't remember ATM which it is (and probably depends on the paltform/widgetset), sorry :-[

I've never had to use something like this, the usual auto-pasting of the text in the memo works well for me, but I can see where it could come in handy, to differentiate between normal editing actions and a text-drop before an OnChange event.

Yes, that's what I mean. Thank you, lucamar.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1440
  • Former Delphi 1-7, 10.2 user
Re: How to capture the OnDrop event on TMemo.
« Reply #7 on: April 10, 2021, 08:30:12 am »
From the Wiki:
Quote
Major Shortcomings
* The same flaws as Delphi's VCL.
* No LCL framework (cross-platform) support for dragging from an LCL application to any other application. For this to work, LCL needs support for the XDND protocol under X11, OLE Drag-n-Drop support under Windows and Mac Drag Manager under macOS.
* No LCL framework (cross-platform) support for receiving drops inside an LCL application from another application (desktop, file manager, etc). The OnDragDrop event handler always expects the Source of the drop to come through as a TObject descendant which will not be the case when dragging an object from another application to a LCL application.
Lazarus 2.1 r65061 FPC 3.3.1 r49223 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.1 r65070 FPC 3.3.1 r49223 macOS 11.2.3 aarch64 Xcode 12.4
Lazarus 2.1 r61574 FPC 3.3.1 r42318 FreeBSD 12.1 amd64 VMware VM
Lazarus 2.1 r61574 FPC 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 FPC 3.2.0 Win10 Parallels VM

tomitomy

  • Full Member
  • ***
  • Posts: 241
Re: How to capture the OnDrop event on TMemo.
« Reply #8 on: April 10, 2021, 11:05:17 am »
From the Wiki:
Quote
Major Shortcomings
* The same flaws as Delphi's VCL.
* No LCL framework (cross-platform) support for dragging from an LCL application to any other application. For this to work, LCL needs support for the XDND protocol under X11, OLE Drag-n-Drop support under Windows and Mac Drag Manager under macOS.
* No LCL framework (cross-platform) support for receiving drops inside an LCL application from another application (desktop, file manager, etc). The OnDragDrop event handler always expects the Source of the drop to come through as a TObject descendant which will not be the case when dragging an object from another application to a LCL application.

Thank you trev, I give up.

lucamar

  • Hero Member
  • *****
  • Posts: 3895
Re: How to capture the OnDrop event on TMemo.
« Reply #9 on: April 10, 2021, 12:39:52 pm »
From the Wiki: [etc]

Would be nice to know where in the Wiki ;)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1440
  • Former Delphi 1-7, 10.2 user
Re: How to capture the OnDrop event on TMemo.
« Reply #10 on: April 10, 2021, 12:43:42 pm »
I was in a hurry ;)  See Major Shortcomings.
« Last Edit: April 10, 2021, 01:14:30 pm by trev »
Lazarus 2.1 r65061 FPC 3.3.1 r49223 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.1 r65070 FPC 3.3.1 r49223 macOS 11.2.3 aarch64 Xcode 12.4
Lazarus 2.1 r61574 FPC 3.3.1 r42318 FreeBSD 12.1 amd64 VMware VM
Lazarus 2.1 r61574 FPC 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 FPC 3.2.0 Win10 Parallels VM

GetMem

  • Hero Member
  • *****
  • Posts: 4017
Re: How to capture the OnDrop event on TMemo.
« Reply #11 on: April 10, 2021, 02:09:47 pm »
@ tomitomy
If you are on windows, there is a DragDrop component(https://packages.lazarus-ide.org/DragDrop.zip), by Anders Melander(fork for Lazarus Michael Köcher). According to the description:
Quote
The Drag and Drop Component Suite is a freeware VCL component Library that enables your Lazarus applications to support COM based drag and drop and integrate with the Windows Clipboard
I don't know if supports "text dropping". Maybe you should pm Michael Köcher(forum user six1) and ask for assistance.
« Last Edit: April 10, 2021, 07:54:34 pm by GetMem »

tomitomy

  • Full Member
  • ***
  • Posts: 241
Re: How to capture the OnDrop event on TMemo.
« Reply #12 on: April 11, 2021, 05:06:49 am »
@GetMem
I'm not on windows, I use Linux, and I want to use only the functions of TMemo itself. But thank you all the same. :)

 

TinyPortal © 2005-2018