VCL Classes: TClipboard |
|
Introduction to the Clipboard |
Description |
The clipboard is an operating system object that is used to temporarily hold an object other that can be copied or moved from one source to a target. To store an object to the clipboard, the user must first copy it. The user has the option of copying or moving. |
By default, the clipboard in Microsoft Windows can hold only one object. Normally, the size and type of the object doesn't matter. The object can be a letter, a word, a sentence, a paragraph, a page, or even a whole book. The object can also be a small icon, a picture, or even a whole video. There is a common clipboard that all applications share and use.
To support the clipboard, the VCL provides a class named TClipboard. The TClipboard class is derived is derived from TPersistent. The TClipboard class is defined in the Clipbrd.hpp header file. |
As mentioned already, all applications that are currently running on the computer share a clipboard. To let you use that common clipboard, when you start an application, the compiler automatically creates a global TClipboard object. This means that you will hardly, if ever, have any reason to explicitly declare a TClipboard variable. The global clipboard variable created by the compiler is a function named Clipboard. Some controls already have complete built-in support for the clipboard. That's the case for text-based controls. For the other controls, you will have to write code.
The clipboard is an operating system object that is available to all applications. To support it, it is represented in the Win32 library as a handle. To let you get this handle in a VCL application, the TClipboard class is equipped with a Handle property: property Handle: HWND read GetClipboardWindow; As you can see, the clipboard is an HWND object.
There are almost no restrictions on the types and sizes of objects that the clipboard can hold. When storing something in the clipboard, probably the first decision you must make is about the type of object you want to keep. The most common type of object used by the clipboard is text. To let you indicate that you are storing text in the clipboard, the TClipboard class is equipped with the AsText property: property AsText: string read GetAsText write SetAsText; In the same, to get the text stored in the clipboard, you can access the value of this property.
As mentioned already, the clipboard is configured to hold various types of objects. These types are referred to as formats. If you decide to put something in the clipboard, you must specify the format of that object. The available formats are:
To let find out what type of format the clipboard currently has, the TClipboard class provides the HasFormat() method. Its syntax is: function HasFormat(Format: Word): Boolean; When calling this method, pass a format to it. If the method returns True, it means that the clipboard is currently holds the type of value you passed. The other characteristics of the clipboard are connected to text-based and picture-based controls. These will be addressed in other lessons. |
|
||
Home | Copyright © 2010-2016, FunctionX | |
|