Lazarus

Programming => General => Topic started by: Packs on February 14, 2025, 08:36:29 am

Title: on form drag and drop file option
Post by: Packs on February 14, 2025, 08:36:29 am
On form there is drag and drop option it is working properly .

I have one form where on top of form lot of panel and memo component.

it is not working because form event can not raised .

how to achieve this 
Title: Re: on form drag and drop file option
Post by: cdbc on February 14, 2025, 11:17:59 am
Hi
Forward the event to the components in question...
Regards Benny
Title: Re: on form drag and drop file option
Post by: Packs on February 14, 2025, 11:21:36 am
Code: Pascal  [Select][+][-]
  1. procedure Tfrminward.FormDropFiles(Sender: TObject; const FileNames: array of string);
  2. begin
  3.   if Length(FileNames) > 1 then
  4.   begin
  5.     ShowMessage('Select one file');
  6.     Exit;
  7.   end;
  8.  
  9.   Opendlg_inward.FileName := FileNames[0];
  10. end;
  11.  

form FormDropFiles event should run.

it is get protected if you have panel or other components in form.
Title: Re: on form drag and drop file option
Post by: cdbc on February 14, 2025, 11:41:59 am
Hi
If your whole form is covered with components, I've found it easiest to just let the /drop/ event-handlers of said components, just point to the same one - namely the one you have for the form...
Regards Benny
Title: Re: on form drag and drop file option
Post by: Packs on February 14, 2025, 11:47:56 am
in that case I have to write event for all component .

it should be simple user will drag and drop any where , my form dragfile event should trigger .
Title: Re: on form drag and drop file option
Post by: cdbc on February 14, 2025, 12:06:37 pm
Hi
No, just point all the components' handlers to the one you have written for the form, they have the same signature. You can do that in the Object Inspector.
Regards Benny
Title: Re: on form drag and drop file option
Post by: Packs on February 14, 2025, 12:09:27 pm
all component is having different signature .

on formdrag event accept file other all accepting x,y position or string
Title: Re: on form drag and drop file option
Post by: cdbc on February 14, 2025, 12:31:29 pm
...Then Google is your friend  ...I guess.

eta: At least you need someone more knowledgeable than me, regarding the intricacies of the LCL.
Title: Re: on form drag and drop file option
Post by: Packs on February 14, 2025, 12:46:58 pm
Ok Sir 👍
Title: Re: on form drag and drop file option
Post by: wp on March 21, 2025, 07:19:24 pm
See https://forum.lazarus.freepascal.org/index.php/topic,70589.msg550415.html#msg550415 for a workaround based on embedded forms.
Title: Re: on form drag and drop file option
Post by: Remy Lebeau on March 21, 2025, 07:32:14 pm
UI controls don't have events for dropping files on them. The OnDragDrop and similar events are meant for drag&dropping other UI controls onto each other.  If you want to accept a file drop onto a child UI control of a Form, then you have to manually register the drag&drop handler yourself.  For instance, on Windows, using either DragAcceptFiles() (https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-dragacceptfiles) or RegisterDragDrop() (https://learn.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-registerdragdrop), and then handling the relevant callback.
TinyPortal © 2005-2018