Seventh chapter-Clipboard and Dynamic Data Exchange (i) (1)

Source: Internet
Author: User
Tags ole

Data exchange between applications is an important feature of a multitasking environment like windows. As a windows-based development tool, Delphi supports the following four types of data interchange: Clipboard, Dynamic Data Exchange (DDE), Object joins and Embedding (OLE), and dynamic Join libraries (DLLs). The first three methods are most commonly used, the OLE function is the most powerful, and the second is DDE. The Clipboard is most convenient to use. In this chapter, we only discuss clipboard and dynamic data exchange. Using OLE to realize data exchange in the next chapter, the use of Dynamic Junction Library (DLLs) for data exchange will be introduced in the tenth chapter.

7.1 Clipboard and its application

In essence, the Clipboard is simply a global memory block. When an application passes data to the Clipboard, the ownership of the associated memory block is transferred from the application to Windows itself by modifying the memory block allocation flag. Other applications can find this block of memory through a handle that can read data from a block of memory. This enables the data to be transmitted between different applications.

Although the Clipboard is simple and does not implement real-time transmission, it is the basis for more complex DDE and OLE. Using the Clipboard is a convenient and quick way for some programs that only occasionally need to use other application data.

Delphi encapsulates most of the functionality of the Clipboard into a Tclipboard class, while placing the most frequently used text transfer features, including Dbimage image transfer, into the appropriate parts as part of the method, making it easy for users to program with the Clipboard.

7.1.1 using the Clipboard to transfer text

Clipboard transfer text is mainly applied to the following three methods: CopyToClipboard, Cuttoclipboard and Pastefromclipboard. The parts that contain these methods are shown in the following table.

Table 7.1 parts that contain the Clipboard method

━━━━━━━━━━━━━━━━━━━━━━━━━━━

Method part

———————————————————————————

Tdbedit Tdbmemo

Tdbimage

Copytoclipboardtedittmemotmaskedit

Tolecontainer

Tddeserveritem

———————————————————————————

Tdbedittdbmemo

Cuttoclipboardtdbimage

Tedittmemotmaskedit

———————————————————————————

Tdbedittdbmemo

Pastefromclipboardtdbimage

Tedittmemotmaskedit

━━━━━━━━━━━━━━━━━━━━━━━━━━━

In addition to Tdbimage, the rest is all about text control.

Text must be selected before the text is transferred to the Clipboard.

If the AutoSelect property of the selected Tmaskedit is true, the text is automatically selected when Maskedit gets input focus, and if the TMemo property of Tedit and HideSelection is true, the text selection is automatically hidden when the focus is lost. Again when the focus is regain.

The following statement cuts the selected text in the Maskedit to the Clipboard:

Maskedit.cuttoclipboard;

The following statement pastes the text from the Clipboard at the current cursor at memo:

Memo.pastefromclipboard;

The use of Clipboard classes also enables the transfer of text, see the introduction in (7.1.2).

7.1.2 Clipboard class

To facilitate the operation of the Clipboard, Delphi defines a Tclipboard class in the CLIPBRD Library unit, and a variable clipboard is predefined as an instance of a class Tclipboard. This allows users to define a Tclipboard instance on most occasions.

Clipboard classes allow you to transfer text, images, and parts, and the Clipboard classes provide the appropriate properties and methods for implementing these methods. Table 7.2, table 7.3, lists the meaning of the Tclipboard properties and methods.

Table 7.2TClipboard's Properties

━━━━━━━━━━━━━━━━━━━━━━━━━━━

attribute meaning

───────────────────────────

Astext saves the text of the Clipboard, only the runtime can set

Number of FormatCount available clipboard formats

Formats available Clipboard format chain

━━━━━━━━━━━━━━━━━━━━━━━━━━━

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.