juhara.com

  • Narrow screen resolution
  • Wide screen resolution
  • Decrease font size
  • Default font size
  • Increase font size
Home Articles Delphi Programming Copy paste data from clipboard
Copy paste data from clipboard PDF Print E-mail
Written by Zamrony P. Juhara   
Wednesday, 29 April 2009 12:17
Article Index
Copy paste data from clipboard
Clipboard Implementation
Creating Demo Application
Demo Implementation
All Pages

This class I wrote to encapsulate copying custom data from or to clipboard. I was in a situation where, software I develop must have feature to copy or paste data in particular format to clipboard. After googling around, I found solution and started writing its implementation and encapsulated it into a class.

Copy data from or to clipboard.

Design

This class is derived from TPersistent and maintaining an internal buffer where its lifetime is managed by class. To make it flexible, this class is only responsible to copy data. Data format and how to interpret data is defined and implemented by application.

We need following units : classes, windows, clipbrd. We name class that we are going to develop TClipboardCopier. This class will have following methods:

  • Create (constructor)
  • Destroy (destructor)
Constructor and destructor contain internal buffer initialization code.
  • AssignTo(Dst:TPersistent)
  • Assign(src:TPersistent)
Assign and AssignTo of TPersistent is overriden so this class has ability to do assignment from and to clipboard. Data that is copied is taken from internal buffer. Assume clipCopier is instance of TClipboardCopier:
clipCopier.Assign(Clipboard);
Code above will copy clipboard content to clipCopier (paste operation). Or,
clipboard.Assign(clipCopier);
will copy content in clipCopier into clipboard (copy operation). AssignTo, just like in TPersistent, is protected, Assign is public.
  • AssignToClipboard(Dst:TClipboard)
  • AssignClipboard(src:TClipboard);
AssignToClipboard, AssignClipboard are procedures that handle actual data copy. Respectively, called by AssignTo and Assign.
  • procedure SaveToStream(Stream:TStream)
  • procedure LoadFromStream(Stream:TStream)

LoadFromStream and SaveToStream is used to copy data from and to internal buffer of instance of TClipboardCopier class.

We will define a property:

  • Format :word

Holds clipboard data format returned by Windows API, RegisterClipboardFormat(). Application must register clipboard format first.



Last Updated on Friday, 06 November 2009 15:18
 

Language

IndonesianEnglish (United Kingdom)

Game Institute
DAZ3D

Is this article helpful? Help this site improve by donating. Any amount is appreciated.