1 (edited by sdhale29 2020-04-07 02:14:37)

Topic: OnDropFiles Copy Dropped File to Folder

Can anyone give me an example on how to use OnDropFiles To Copy the dropped file or files to a folder in a specific directory?  In my case I am trying to drop the files on a tablegrid .

Thank you in advance

Sonny.

Re: OnDropFiles Copy Dropped File to Folder

procedure Form1_OnDropFiles (Sender: TObject; ArrayOfFiles: array of string; X, Y: Integer);
var
    i, c: integer;
    folder: string;
begin
    folder := 'e:\temp\';
    c := Length(ArrayOfFiles)-1;
    for i := 0 to c do
    begin
        CopyFile(ArrayOfFiles[i], folder+ExtractFileName(ArrayOfFiles[i]));
    end;
end;
Dmitry.

Re: OnDropFiles Copy Dropped File to Folder

DriveSoft wrote:
procedure Form1_OnDropFiles (Sender: TObject; ArrayOfFiles: array of string; X, Y: Integer);
var
    i, c: integer;
    folder: string;
begin
    folder := 'e:\temp\';
    c := Length(ArrayOfFiles)-1;
    for i := 0 to c do
    begin
        CopyFile(ArrayOfFiles[i], folder+ExtractFileName(ArrayOfFiles[i]));
    end;
end;

Thank You Dmitry, i'll give it a try.

Sonny.

Re: OnDropFiles Copy Dropped File to Folder

Dmitry it works great, but I am having a hard time figuring out how to update the grid with the file information.

Sonny.

Re: OnDropFiles Copy Dropped File to Folder

sdhale29,
Tablegrids are used to display records in a table. So in order to display the dropped files info in a tablegrid you need to create a table to hold the file info and then define a tablegrid to display the records. I created a small project to demonstrate it. I kept Dimitry's code in place and added the table inserts and grid update. I also deleted all records and cleared the tablegrid rows upon Form1 OnShow event. If you need to keep the records in your project, you can remove the procedure.

Post's attachments

Attachment icon Drop Files into Tablegrid.zip 336.81 kb, 330 downloads since 2020-04-13 

6 (edited by sdhale29 2020-04-13 05:07:33)

Re: OnDropFiles Copy Dropped File to Folder

ehwagner wrote:

sdhale29,
Tablegrids are used to display records in a table. So in order to display the dropped files info in a tablegrid you need to create a table to hold the file info and then define a tablegrid to display the records. I created a small project to demonstrate it. I kept Dimitry's code in place and added the table inserts and grid update. I also deleted all records and cleared the tablegrid rows upon Form1 OnShow event. If you need to keep the records in your project, you can remove the procedure.

Thank you ehwagner, I was loading them into a table, but could not get the filenames to show up correctly.  It would list the same filename on all entries.  With your help i figured out how to copy them and get the new file and path name to load correctly.  Thanks again!!!!

Sonny.