1. Home
  2. Computing & Technology
  3. Delphi Programming

Get Filenames from Clipboard

By Zarko Gajic, About.com

"If I use the Windows Explorer to copy a file, how can I use the paste function in my application?"

This code retrieves the filenames from the clipboard to a memo component. Drop a memo and a button on a form and set the OnClick of a button to:

~~~~~~~~~~~~~~~~~~~~~~~~~
uses
   clipbrd, shellapi;

procedure TForm1.Button1Click(Sender: TObject) ;
var
   f: THandle;
   buffer: Array [0..MAX_PATH] of Char;
   i, numFiles: Integer;
begin
   Clipboard.Open;
   try
     f:= Clipboard.GetAsHandle( CF_HDROP ) ;
     If f <> 0 Then Begin
       numFiles := DragQueryFile( f, $FFFFFFFF, nil, 0 ) ;
       memo1.Clear;
       for i:= 0 to numfiles - 1 do begin
         buffer[0] := #0;
         DragQueryFile( f, i, buffer, sizeof(buffer)) ;
         memo1.lines.add( buffer ) ;
       end;
     end;
   finally
     Clipboard.close;
   end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Cut a rectangle from an Image to Clipboard
« Hide the Clock icon on Windows Tray

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2001 Delphi Tips
  7. Get Filenames from Clipboard

©2009 About.com, a part of The New York Times Company.

All rights reserved.