Recent

Author Topic: Drag/Drop text from another app to a TEdit  (Read 3181 times)

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Drag/Drop text from another app to a TEdit
« on: July 04, 2021, 10:06:22 pm »
Win7 64bit, laz 2.0.12, FPC 3.2.0
I need to be able to drag text from another app (browser or text-editor) and drop it on a TEdit (clipbord is used for other stuff, so copy/paste is not a solution).
And actually, I figured, why not create the thing as a componemt, so it can be used in other applications as well...?

So - a Form with a TEdit.
Nothing else for a start.
Plan was to use Melanders (DragDropLazarus 5.2.0.0 Installed from online - and demos functioning. Unfortunately, there are no demo of using DragTextTarget...)
Creating a OnDragOver handler for the TEdit.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Edit1DragOver(Sender, Source: TObject; X, Y: Integer;
  2.   State: TDragState; var Accept: Boolean);
  3. begin
  4.   Accept := true;
  5. end;
  6.  
Running the app, it is never called. Neither in Debug nor normal mode.
Added a TDropTextTarget and set TEdit1 as Target.
That raises an exception (Compiles fine, but gies a runtime esception):
Quote
TEdit can't have a control of class TWinControlProxy as a child

So what am I missing?
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

jamie

  • Hero Member
  • *****
  • Posts: 4837
Re: Drag/Drop text from another app to a TEdit
« Reply #1 on: July 05, 2021, 03:03:51 am »
did you look at this?

https://wiki.freepascal.org/Drag_and_Drop_sample


also look for "Advanced Drag & Drop - Free Pascal" Pdf.
The only true wisdom is knowing you know nothing

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: Drag/Drop text from another app to a TEdit
« Reply #2 on: July 05, 2021, 11:32:47 am »
Yes - and a lot of other stuff, floating around.  :o :)
I do understand the principles.

Problem with Melanders seems to be some kind of typing - you can set a TPanel as a Target.
TPanel can then show the text as Caption - which is not really what is needed.
Should be possible to Drag/Drop to a TEdit or TMemo (and possibly other text-handling types) when dragging text.

Created my own version of TDropTextTarget, which allows for that - TEdit(s) do still need to be placed on a TPanel, and that panel be the Target of TMyDropTextTarget.

Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: Drag/Drop text from another app to a TEdit
« Reply #3 on: July 05, 2021, 10:13:24 pm »
Did anybody ever create an app that will accept drops from other apps, that are not created with Melanders components?

I have an editor that drags text out of it - using Melanders components.
I can drop these strings, and also from NP++.

But not from the IDE, and not from my browser.
Anybody has any ideas?
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

jamie

  • Hero Member
  • *****
  • Posts: 4837
Re: Drag/Drop text from another app to a TEdit
« Reply #4 on: July 05, 2021, 10:32:11 pm »
Yes, I've done file link drops. I also believe browsers do the same, they generate file link path to the object. Mostly string data.

 TForm and TApplication has that I believe.
The only true wisdom is knowing you know nothing

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: Drag/Drop text from another app to a TEdit
« Reply #5 on: July 06, 2021, 04:35:13 pm »
I tried accepting dtLink - and it makes no difference. Also have dtCopy and dtMove active.
I tried setting the form to accept links, and it makes no difference.

Melanders TDropTextTarget simply never acitvates DragOver, when draggin from browser (FF).
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

 

TinyPortal © 2005-2018