




| Copy paste data from clipboard |
|
|
|
| Written by Zamrony P. Juhara | ||||||
| Wednesday, 29 April 2009 12:17 | ||||||
Page 1 of 4 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.DesignThis 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:
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, AssignClipboard are procedures that handle actual data copy. Respectively, called by AssignTo and Assign.
LoadFromStream and SaveToStream is used to copy data from and to internal buffer of instance of TClipboardCopier class. We will define a property:
Holds clipboard data format returned by Windows API, RegisterClipboardFormat(). Application must register clipboard format first. |
||||||
| Last Updated on Friday, 06 November 2009 15:18 |