Drag and Drop Files. Which Control Received the Drop? lazarus / 21-General ---------------------------------------------------------------------- local-vision · 2021-02-15 22:44 Drag and drop a file onto the form and get the file name is easy: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    Memo1: TMemo;    Panel1: TPanel;    procedure FormCreate(Sender: TObject);    procedure FormDropFiles(Sender: TObject; const FileNames: array of String);  private    public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } {I would want to know if the file was specifically dropped onto Panel1 or not} procedure TForm1.FormCreate(Sender: TObject);begin  AllowDropFiles:=True;end; procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of String);var  n: Integer;begin  //  Sender is always TForm, never TPanel  //  if sender is TPanel then begin ShowMessage(TPanel(Sender).Name); end; /this does not get called  //  if sender is TForm then begin ShowMessage(TForm(Sender).Name); end; // this gets called   Memo1.Clear;  for n := Low(FileNames) to High(FileNames) do  begin    Memo1.Lines.Add(FileNames[n]);   end;end; end.                    However, I want to know if the file was specifically dropped onto the Panel1 or not. Any ideas? ---------------------------------------------------------------------- Handoko · 2021-02-16 01:57 jamie answered faster. Well, this is the code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of String);var  MousePoint: TPoint;  n: Integer;begin   MousePoint := ScreenToClient(Mouse.CursorPos);  case PtInRect(Panel1.BoundsRect, MousePoint) of    True:  Caption := 'You just dropped a file onto the panel.';    False: Caption := 'You didn''t dropped the file onto the panel.';  end;   Memo1.Clear;  for n := Low(FileNames) to High(FileNames) do  begin    Memo1.Lines.Add(FileNames[n]);   end; end; For the position comparison you do it using several if-condition tests or  use PtInRect function. Before doing it, you need to set the coordinate origin to the form by using ScreenToClient. Also you have to put Types unit in the uses clause. ---------------------------------------------------------------------- local-vision · 2021-02-16 22:22 Many thanks to you both for the quick response and solutions! ---------------------------------------------------------------------- local-vision · 2021-02-18 17:09 Hi Jamie, Unfortunately all I get with ControlAtPos is nil. Could you elaborate more on your approach or provide working code. Many thanks. ---------------------------------------------------------------------- local-vision · 2021-02-18 17:23 Found it: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  var  MousePoint: TPoint;  Control:TControl;   begin     MousePoint := ScreenToClient(Mouse.CursorPos);    Control := ControlAtPos(MousePoint, [capfRecursive, capfAllowWinControls]);      {capfAllowDisabled,   // include controls with Enabled=false     capfAllowWinControls,// include TWinControls     capfOnlyClientAreas, // use the client areas, not the whole child area     capfRecursive,     // search recursively in grand childrens     capfHasScrollOffset, // do not add the scroll offset to Pos (already included)     capfOnlyWinControls  // include only TWinControls (ignore TControls) }        if Assigned(Control) then    begin      Memo1.Lines.Add(Control.Name);    end else    begin      Memo1.Lines.Add('Notin found');    end;  end; ---------------------------------------------------------------------- Handoko · 2021-02-18 17:29 I've just wanted to post the answer. But glad to see you found it yourself. Yes, many questions can be answered by reading the documentation or examining the source code. ---------------------------------------------------------------------- local-vision · 2021-02-18 20:13 Handoko, Correct and appreciated! Yes consult the docs. Yet, still always looking for new ways to dealing with old things. And, in this case its input like yours that is valued. I was getting NILs due to the settings such as capfAllowWinControls not being set right. As soon as I got the settings right all was well. For clarity I copied the possible settings from the Controls.pp unit here in the code as comments.