Drag an drop a text file to a delphi form

Hello,

I want do do this :

- I get some mails with a particular text file (REG.TXT) attached.

- I want to do this : Open the mail in OutLook Express, click on the REG.TXT icon (attached file), drag and drop the REG.TXT on my Delphi app.

- Then read the contents of REG.TXT in my app.

How do this ? I want some working sample ...

Best regards,

Jean-Pol
jpdupontAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LischkeCommented:
Hi Jean-Pol,

the easiest way is surely to use the drop files API (another but much more complex option would be to use interfaces).

During initialization of your program make your main window accepting dropped files by calling:

  DragAcceptFiles(Handle, True);

The write a message handler for this window (form):

type
  TMyForm = class(TForm)
  private
    procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES;
  end;

procedure TMyForm.WMDropFiles(var Msg: TWMDropFiles);

// the common game here if a file has been dropped on the application

var
  Buffer: array[0..MAX_PATH] of Char;
  Count, I: Integer;
  List: TStringList;

begin
  Count := DragQueryFile(Msg.Drop, DWORD(-1), nil, 0);
  List := TStringList.Create;
  for I := 0 to Count - 1 do
  begin
    DragQueryFile(Msg.Drop, I, Buffer, MAX_PATH);
    List.Add(Buffer);
  end;
  AddProjectFiles(List);
  List.Free;
  DragFinish(Msg.Drop);
  Msg.Result := 0;
end;


AddProjectFiles is the place you need to act. For instance you can use a memo like:

  Memo1.Lines.LoadFromFile(List[0]);

Ciao, Mike
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kretzschmarCommented:
or get just the drag&drop components from

www.melander.dk

meikl
0
LischkeCommented:
..adding OLE and COM/ActiveX stuff just to accept a text file :-)

Ciao, Mike
0
jpdupontAuthor Commented:
Meikl,

thanks for the link.

===

Mike,

I try your code : fine !!!
I give you the points and the A grade.

1/ I don't understand your comment with OLE and COM ... Could you explain me ?

.... I just set "uses shellapi" in my code.

2/ What's the best value for MAX_PATH ?

Thanks,

Jean-Pol
0
LischkeCommented:
Well, Anders Melander's stuff is great for general purpose drag'n drop between applications. This involves, though, to include units into your application which will add the OLE stuff. If this is not already used by your application then you will get a large overhead just for a small task.

MAX_PATH is already defined (being 260 if I recall correctly). Look into Windows.pas.

Ciao, Mike
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.