Solved

TMemo drag and drop

Posted on 2004-03-30
13
763 Views
Last Modified: 2010-04-16
Supposed to be easy: how to drag and drop a file from windows explorer in a TMemo?

Thank you!
0
Comment
Question by:__alex
  • 7
  • 3
  • 2
  • +1
13 Comments
 

Expert Comment

by:rafamvc
ID: 10714620
why tmemo? are u planning to receive a txt file?
0
 
LVL 2

Author Comment

by:__alex
ID: 10714671
For the sake of simplicity: Yes.
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 125 total points
ID: 10714862
NOTE:  Uses SHellAPI

Shane



unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ShellApi;


type
  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure WMDROPFILES(var Message: TWMDROPFILES); message WM_DROPFILES;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.WMDROPFILES(var Message: TWMDROPFILES);
var
  NumFiles : longint;
  i : longint;
  buffer : array[0..255] of char;
begin
 {How many files are being dropped}
  NumFiles := DragQueryFile(Message.Drop,
                            0,
                            nil,
                            0);
 {Accept the dropped files}
  for i := 0 to (NumFiles - 1) do begin
    DragQueryFile(Message.Drop,
                  i,
                  @buffer,
                  sizeof(buffer));
    Form1.Memo1.Lines.Add(buffer);
  end;

end;


procedure TForm1.FormCreate(Sender: TObject);
begin
 {Let Windows know we accept dropped files}
  DragAcceptFiles(Form1.Handle, True);
end;

end.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 10715522
shane,
i guess alex wants to open the file which was dropped
(in case of a text-file),
not a filelist

still listening . . .

meikl ;-)
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10715555
Have you tried the code meikl,

it will allow you to drag a text file and drop it into your TMemo.
I didn't provide the Error checking, so this assumes that the file is a Text File

Shane
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10715974
no, i didn't tried, i guess it works,
but i see that you fill the memo with the dropped filenames,
and i guess, alex want to fill the memo with content of a dropped text-file

meikl ;-)
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10716069
Oh, I see .. i had a brain fart - <smile>

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10716083
So I guess he could alter it,  to load the file versus add the file name to it.

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10716103
Off the top of my head, something like:

Shane

procedure TForm1.WMDROPFILES(var Message: TWMDROPFILES);
var
   buffer : array[0..255] of char;
begin
   DragQueryFile(Message.Drop,
                  i,
                  @buffer,
                  sizeof(buffer));
    Form1.Memo1.Lines.LoadFromFile(buffer);
  end;

end;
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10716127
sorry

procedure TForm1.WMDROPFILES(var Message: TWMDROPFILES);
var
   buffer : array[0..255] of char;
begin
   DragQueryFile(Message.Drop,
                  0,
                  @buffer,
                  sizeof(buffer));
    Form1.Memo1.Lines.LoadFromFile(buffer);
end;

Shane

0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10717090
yep, only a smart change ;-))

but i owuld left out form1 here

>Form1.Memo1.Lines.LoadFromFile(buffer);

just

>Memo1.Lines.LoadFromFile(buffer);

(becaue you are in the TForm-object with this method,
whereas form1 may point to another instance,is  nil or points to somewhere)

meikl ;-)
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10717147
yeah, i type faster than i think...<smile>

Shane
0
 
LVL 2

Author Comment

by:__alex
ID: 10721490
Works great, thanks!
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question