This forum is temporaily read-only. All existing discussions remain available for reference. For new questions, bug reports or support requests, please contact us at mail@lmdsupport.com.

Use of TNGDropTarget????

Hi Guys,
Using D10.4.1, Win 10, Latest LMD NG.
I am wrestling with understanding TNGDropTarget.  What I am after may in fact not be possible.  I don't know. :-(  I find the terminology and descriptions in the components help confusing.
I want to be able to do two things..
1.  Drag & Drop a file from Windows Explorer and drop the file name, including path, into a TEdit.Text.
2.  Drag & Drop an image file (.jpg, .jpeg, .png) to a TImage.Picture.
Can TNGDropTarget do this?
If yes, I would appreciate very much an example of each of the above.

Regards & TIA,
Ian

Comments

  • edited December 2020
    Here an example for edit:

    procedure TForm11.FormCreate(Sender: TObject);
    begin
      NGDropTarget.Register(Edit1, procedure(C: TNGTargetContext)
      var
        fls: TNGStrArray;
      begin
        if C.Accept(CF.HDROP.Ref(@fls)) then
        begin
          if Length(fls) > 0 then
            Edit1.Text := fls[0];
        end;
      end);
    end;

    TImage is not a TWinControl, so to use drag&drop you have to place it into some parent control, like TPanel:

    procedure TForm11.FormCreate(Sender: TObject);
    begin
      NGDropTarget.Register(Panel1, procedure(C: TNGTargetContext)
      var
        fls: TNGStrArray;
      begin
        if C.Accept(CF.HDROP.Ref(@fls)) then
        begin
          if Length(fls) > 0 then
            Image1.Picture.LoadFromFile(fls[0]);
        end;
      end);
    end;
  • Excellent.  Thank you.
Sign In or Register to comment.