Using DDE to interact with Word in Delphi

Source: Internet
Author: User
Tags require

First, the introduction

Windows supports three basic IPC (interprocess communication) Mechanisms: Shared data segments in dynamic-link libraries (DLLs), Windows clipboard (Clipboard), and Dynamic Data exchange DDE. Many well-known Windows applications, such as Microsoft Word, declare support for DDE technology and EMBED DDE message processing functions in programs. This type of application is most commonly used as a DDE server in terms of DDE technology, this allows the user to connect to the DDE client through some of its own peripheral software, and to perform dynamic control of the server program by sending some specific macro commands to the DDE server program. This article takes a common example of Microsoft Word to describe how to prepare a DDE client in the Delphi programming environment to dynamically control the general methods of Microsoft Word.

Second, the working principle of DDE

As the name suggests, DDE is a general technique for the dynamic exchange of data during the running of different programs. Although Windows messages are the best means of transmitting information between different program windows, a message can contain only two parameters (WPARAM and lparam) and cannot transmit more information. Memory blocks are an important means of storing more information, but they do not support the sharing of global memory handles. DDE is a protocol built on the Windows internal messaging system, global atom, and shared global memory, which is used to reconcile data exchange and command calls between Windows applications.

The DDE protocol uses level three naming: Service, subject (topic), and data items (item) to identify the data cells that are passed by DDE. Services enable applications to have the ability to exchange data with other programs, the General Service being the file name of the application, such as the service of Word is winword (executable is Winword.exe), and the topic is a meaningful unit of information for the server, which is a good topic for Word documents. Many servers have a default theme system, but you cannot know exactly which topics the server has, unless you consult the relevant technical documentation for your application. Each DDE client and service program is initiated by the customer first, so the DDE server must be operational before each customer starts, and the following is a typical transaction component of a DDE session process:

• Client program automatic session, server program response.

• Customers and servers Exchange data in the following ways:

• The server sends data to the customer at the customer's request;

• Customer initiative to send data to the server;

• Customers require the server to send data when data is modified (hot data connection);

• Customers require the server to send a notification after data modification (temperature data connection);

• At the request of the customer, the server executes a command.

• Session aborted by client or server.

Third, design ideas

First, on the choice of development tools, choose Borland Delphi 5.0, which provides ready-made DDE series components. Now that you have Microsoft Word as the server to connect to, set up the service and the subject of the connection before you establish the connection, because this example only requires a few actions in Word, such as opening a new file, closing a file, inserting a table, and so on, so you can set these two separately: " Winword "and" System ", when the connection can be set up through the Delphi provided by the Ddeclientconv component of the OpenLink function to open the connection to the service, the rest of the work is to send a macro command to the word server, And through the component to send it to execute the macro command can be implemented with the function of the component Executemacro.

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.