How to Get Filenames from Clipboard ?

CK CK 3788 
Created at
Updated at  
1,503 0 0

"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;
Tags DragQueryFile Extract Filenames from Clipboard Get Available System Memory Information chkdsk Facebook X
Comments 0
Similar posts
  1. How to Get Windows OS Version ?
    429
  2. Get system info (free memory, etc)
    405
  3. Get dimensions of usable space on monitor (work area)
    490
  4. Get Windows Temp directory
    658
  5. Get text from the control at pos x,y on screen
    469
  6. How to determine the output of a console application ?
    451
  7. How to install an INF file using Delphi ?
    463
  8. How to play sounds on the PC Speaker ?
    528
  9. Disable ALT+TAB, CTRL+ESC, CTRL+ALT+DEL
    1,827
  10. Display Standard Windows Properties dialog
    1,129
  11. Disable Mouse and Keyboard from Delphi Code
    795
  12. Detecting Drive Types
    467
  13. Detecting and preventing Windows shut down
    439
  14. Copying Group of Files using Delphi with Standard Animation Dialog (SHFileOperation)
    413
  15. Controling sound volume from code
    424
  16. How to Close Another Application by Windows Caption
    390
  17. How to Change the Windows Start button bitmap
    428
  18. How to capture the output from a DOS (command/console) Window
    965
  19. How to Activate/Deactivate the Screen Saver
    863
  20. How to remove your application from TaskBar
    659
  21. How to track a user's idle time
    589
  22. How to know whether the font is TrueTypeFont or not
    378
  23. List Devices (LPT, COM ports, ...)
    478
  24. How to restrict mouse movement
    408
  25. How to send char as message to another application
    544
  26. How to save text from Clipboard to a file
    569
  27. How to show window contents while dragging
    455
  28. How to use TTF Font Without Installing
    1,117
  29. Window flashing
    379
  30. Copy text to clipboard in Javascript
    1,715
  1. How to encode subject content when sending mail with TIdMessage ?
    1,072
  2. Base64 Encoding/Decoding function for Delphi
    1,154
  3. How to send email by TIdSMTP VCL ?
    1,019
  4. How to return exit code such as exit() function in C/C++ ?
    666
  5. How to get parameter string ?
    1,240
  6. Save TBitmap image to Jpeg format image in Delphi
    712
  7. How to get screen resolution in case of using multiple monitors ?
    450
  8. How to turn off monitor ?
    429
  9. Find File at certain directory in Delphi
    437
  10. Sending email messages in .Net
    1,035
  11. Delphi for .Net Code Folding keyboard shortcuts
    527
  12. How to encrypt a string
    467
  13. Creating thumbnail images
    861
  14. Technology sharing related with software development. Specially content will be focused to programming language, and embedded systems.
    851
  15. How to speed up access to the RichTextBox Lines property
    831
  16. Retrieving all image links from an HTML document
    419
  17. List All Network Drives
    392
  18. How to set the "home page" for the Internet Explorer from Delphi code
    431
  19. How to get get IE favorites
    454
  20. Extracting the domain (host) name from an e-mail address
    488
  21. Download a file from the Internet with progress indicator
    553
  22. Are we connected to the Internet?
    422
  23. TImage.Bitmap fade out
    373
  24. TDesktopCanvas - draw on Windows Desktop
    558
  25. TColor to HTML color
    415
  26. Show *any* graphics as Glyph on a SpeedButton
    542
  27. Rotating Text
    448
  28. Paint a Form with a tiled bitmap image
    413
  29. Is Point in Polygon?
    368
  30. Implementing a lasso drawing technique
    385
Recently updated
  1. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    42
  2. Why SPF and DKIM Are Essential for Linux Email Servers?
    36
  3. How do I create animated background for Google Meet?
    21,044
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    252
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    94
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    157
  7. Array of arguments passed to script in PHP
    90
  8. Invalid Auction Storms in Ad Tech
    98
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    202
  10. The Two Clocks of Ad Server Architecture
    71
  11. Frequency Cap Architecture Overview
    515
  12. Collecting Proof-of-Play from 100,000 Screens
    146
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    288
  14. What is RedisVL?
    109
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    232
  16. TPU & GPU Cluster Management Tools
    245
  17. The Concept of Scaffolding in AI Agents
    234
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    583
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    259
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    339
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    202
  22. Machine Learning: Training vs. Ranking
    222
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    222
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    195
  25. Designing a Data Curation System Around a Vector Database
    221
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    257
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    656
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    196
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    219
  30. Understanding Data Lineage
    263