Recent

Author Topic: FormDropFiles sends data to an object on the Form also  (Read 4100 times)

fedkad

  • Full Member
  • ***
  • Posts: 176
FormDropFiles sends data to an object on the Form also
« on: February 27, 2018, 03:33:52 pm »
To drop files names to an application I use the main Form's onDropFiles event. This event, when fired, will give an array of file names being dragged-and-dropped to the application window like this:

Code: Pascal  [Select][+][-]
  1. procedure TMainForm.FormDropFiles(Sender: TObject;
  2.   const FileNames: array of String);
  3. begin
  4.   // process FileNames array as you like!
  5. end;
                       

However, in Linux, a memo component that resides on the form will also have the text in FileNames array appended to it (if the user drops the mouse pointer on this memo of course). This behavior is strange, because the memo component is not prepared to accept drop events.

Such a behavior is not present in Windows.
« Last Edit: February 27, 2018, 03:39:56 pm by fedkad »
Lazarus 2.2.6 / FPC 3.2.2 on x86_64-linux-gtk2 (Ubuntu/GNOME) and x86_64-win64-win32/win64 (Windows 11)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8747
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: FormDropFiles sends data to an object on the Form also
« Reply #1 on: February 27, 2018, 07:54:38 pm »
Could be DE/widgetset specific. At least it doesn't happen on my KDE Plasma using Qt backend.

fedkad

  • Full Member
  • ***
  • Posts: 176
Re: FormDropFiles sends data to an object on the Form also
« Reply #2 on: February 28, 2018, 10:26:44 am »
I have this problem both in Lazarus 1.8.0 and 1.9.0 (latest SVN). OS is Ubuntu Linux 17.10 / x86_64-linux-gtk2.
Lazarus 2.2.6 / FPC 3.2.2 on x86_64-linux-gtk2 (Ubuntu/GNOME) and x86_64-win64-win32/win64 (Windows 11)

Thaddy

  • Hero Member
  • *****
  • Posts: 14210
  • Probably until I exterminate Putin.
Re: FormDropFiles sends data to an object on the Form also
« Reply #3 on: February 28, 2018, 10:37:22 am »
Such a behavior is not present in Windows.
Well that seems so, but isn't the case: windows just has a better understanding and separation of clipboard formats. Once you ask different formats even Windows has the same behavior.
Specialize a type, not a var.

fedkad

  • Full Member
  • ***
  • Posts: 176
Re: FormDropFiles sends data to an object on the Form also
« Reply #4 on: February 28, 2018, 10:47:34 am »
This is a drag and drop operation from the file manager towards the application. I couldn't understand its relationship with the clipboard Thaddy.
Lazarus 2.2.6 / FPC 3.2.2 on x86_64-linux-gtk2 (Ubuntu/GNOME) and x86_64-win64-win32/win64 (Windows 11)

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: FormDropFiles sends data to an object on the Form also
« Reply #5 on: February 28, 2018, 11:20:31 pm »
In windows a chunk of global memory is allocated which contains the list of file names in it.

 The WM_DropFiles is received which has the handle to this memory chunk

 DragQueryFile and DragQueryPoint are used to examine the memory and drop location.

 Last time I knew the clipboard isn't used.
The only true wisdom is knowing you know nothing

fedkad

  • Full Member
  • ***
  • Posts: 176
Re: FormDropFiles sends data to an object on the Form also
« Reply #6 on: March 01, 2018, 11:50:52 am »
  • Create a new project and a new form.
  • Add a memo and a label to the form.
  • Enable the AllowDropFiles property of the form.
  • Add the following code to the OnDropFiles event of the form:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of String
  2.   );
  3. var
  4.   i : Integer;
  5. begin
  6.   label1.Caption := '';
  7.   for i:=low(FileNames) to high(FileNames) do
  8.     label1.Caption := label1.Caption + LineEnding + FileNames[i]
  9. end;

Then run the application and  drag-drop some files from Nautilus (file manager) to the application. Label1 should display their names. If you drop the files to Memo1 instead of an empty area on the form, a string containing the file names will be added to Memo1 contents.

For more strange things do this:

Select some text from Memo1 and try to drag-drop it somewhere within Memo1 (something that you cannot do if the application were run in Windows). The contents will be moved, but some garbage will be displayed in Label1 (see attached screenshot), because the OnDropFiles event of the form is fired!
Lazarus 2.2.6 / FPC 3.2.2 on x86_64-linux-gtk2 (Ubuntu/GNOME) and x86_64-win64-win32/win64 (Windows 11)

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: FormDropFiles sends data to an object on the Form also
« Reply #7 on: March 01, 2018, 07:12:52 pm »
I cannot reproduce that with Lazarus trunk on Linux Mint 18.2.

If I build for GTK then I cannot drop anything on the TMemo, only on the Form.
If I build for QT, I can drop anywhere, but it only fires the Form's OnDropFiles: nothing at all happens with the TMemo.
Note: I have Dolphin as filemanger, not Nautilus.

Bart

Leledumbo

  • Hero Member
  • *****
  • Posts: 8747
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: FormDropFiles sends data to an object on the Form also
« Reply #8 on: March 01, 2018, 07:13:49 pm »
For more strange things do this:

Select some text from Memo1 and try to drag-drop it somewhere within Memo1 (something that you cannot do if the application were run in Windows). The contents will be moved, but some garbage will be displayed in Label1 (see attached screenshot), because the OnDropFiles event of the form is fired!
Sounds like a gtk2 bug. Try reproducing with qt, just to make sure the culprit is indeed the widgetset. With that checked, file a bugreport against gtk2 widgetset.

fedkad

  • Full Member
  • ***
  • Posts: 176
Re: FormDropFiles sends data to an object on the Form also
« Reply #9 on: March 04, 2018, 11:00:35 am »
When I try to compile for anything different than the default gtk2 (in Project Options...|Additions and Overrides) I get a bunch of compile and / or link errors. I even tried, Clean up and Build. So, I am only able to test with gtk2.

I opened a bug report ( https://bugs.freepascal.org/view.php?id=33292 ), but it is still in "new" status.
« Last Edit: March 04, 2018, 11:02:56 am by fedkad »
Lazarus 2.2.6 / FPC 3.2.2 on x86_64-linux-gtk2 (Ubuntu/GNOME) and x86_64-win64-win32/win64 (Windows 11)

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: FormDropFiles sends data to an object on the Form also
« Reply #10 on: March 04, 2018, 03:05:09 pm »
You need to install the fpc bindings for QT.
Look in the wiki for QT, there's a link there that explians howto.
Even I succeeded in doing that on 2 successive Linux distro's (3, because of dying hardware).

Bart

 

TinyPortal © 2005-2018