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

Source: Internet
Author: User
Tags manual join

7.3.2 and DDE server contacts

Contact the DDE server, either at design time or at run time.

At design time, a DDE join can be pasted through the clipboard. The specific steps are as follows:

1. Activate the server program and select the data that your client program wants to connect to;

2. Copy data and DDE connection information to the Clipboard. In general this only needs to select the edit| of the server application Copy menu;

3. In the Delphi IDE design form to select the Ddeclientconv parts;

4. Click the Ddeservice property or Ddetopic property in Object Inspector (Observer), and then click the ellipsis button to open the DDE Info dialog box;

5. Select the Paste Link button. The app edit box and the topic edit box are automatically populated at this time. If the Paste Link button is dimmed, the application you are preparing to use as a server does not support DDE or DDE information that has not been successfully copied to the Clipboard;

6. Select the OK button. The Ddeservice, Ddetopic property in Object Inspector contains the correct values to establish a DDE join.

The following steps are not required for manual mode.

7. Select the Ddeclientitem part and set the Ddeconv property to the Ddeclientconv part name of the completed join in Object Inspector;

8. Select the value of the Ddeitem property from the Drop-down list box in Object Inspector if the DDE join information on the Clipboard is still retained. Otherwise, enter the correct value.

At run time, call the Setlink method to establish a DDE join.

Setlink has two string parameters, which are used to accept values for Ddeservice and Ddetopic, respectively. The Ddeservice and Ddetopic properties of the Ddeclientconv part are set after the procedure is executed. Note that setting the value of Ddeservice and ddetopic directly at run time does not establish a DDE join, and you must invoke the Setlink method for initialization.

For example, the following statement establishes a join with the system theme of Excel:

Ddeclietnconv. Setlink (' Excel ', ' System ');

After calling the Setlink method, you also need to set the Ddeitem property of the Ddeclientitem part.

For example, the following statement joins an Excel topics project to get the file name of the currently active file:

Ddeclietnitem.ddeitem: = ' topics ';

When a DDE join is established, the joined data is saved in the text and lines properties of the Ddeclientitem part, text is used to hold a string (string), and lines is used to hold a string list (TStrings) object.

To display the join data, you can assign a value to a visual part in the Ddeclientitem onchange event.

The following event procedure displays the join data in real time in an edit box.

Procedure Form1.ddeclientitemchange (Sender:tobject);

Begin

Edit1.text: = Ddeclientitem1.text;

End

You can also paste DDE join information from the Clipboard on the run state and call Setlink to establish a DDE session. The following example shows the process of dynamically establishing a DDE session when a user presses the Paste Link button in the application.

Procedure Form1.onpastelink (Sender:tobject);

Var

Service, Topic, item:string;

Begin

If Getpastelinkinfo (Service, Topic, Item) Then

Begin

Appname.text: = Service;

Topicname.text: = Topic;

Itemname.text: = Item;

Ddeclient.setlink (Service, Topic);

Ddeclientitem.ddeconv: = ddeclient;

Ddeclientitem.ddeitem: = Itemname.text;

End

End

Getpastelinkinfo is a process defined in the Ddeman Library unit. If true, the DDE join information is saved in three parameters, and False indicates that the Clipboard does not have the correct form of DDE join information.

7.3.3 Data Request

Although automatic mode is fast and convenient, there are still some reasons to use the manual mode of DDE:

1. The server program may not support automatic data transfer, the customer must explicitly request the server to update a specific project;

2. Save communication costs. If there is no real-time transmission requirements, the manual mode can greatly reduce the cost of communication;

3. If the client program is used only to control the operation of the server, it is often unnecessary to use automatic mode.

In manual mode, the data update of client program needs to adopt the data application method. Data requests need to invoke the RequestData method of the Ddeclientconv part. RequestData has a parameter that points to the DDE project that you want to request. RequestData returns a Pchar string that contains the text of the request. The memory used to return a string must be explicitly disposed before the program terminates.

In manual mode, the value of the text, lines property of the Ddeclientitem part will not change after the data is updated, even if there is a ddeclientitem part and is joined to the Ddeclientconv.

7.3.4 Data Sending

The opposite of the flow of data to normal DDE data is sending data from a DDE client application to a DDE server application.

The data is sent using the Ddeclientconv part of the two methods Pokedata and Pokedatalines, their syntax is:

function Pokedata (item:string; Data:pchar): Boolean;

function Pokedatalines (item:string; data:tstrings): Boolean;

The parameter item is the item that is being joined in the DDE server, and data is the one to send. If the data is a string, convert it to a Pchar type and invoke the Pokedata method, or call the Pokedatalines method if the data is a string list object.

The return value of the method flags whether the data transfer was successful. Because there are some DDE server applications that do not receive the sent data.

The following statement sends the contents of the edit box to the server:

Strpcopy (TheText, Edit1.text);

Ddeclientconv1.pokedata (Ddeclientitem1.ddeitem, thetext);

The procedure strpcopy copies a Pascal-type string into a Pchar type string with no terminator.

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.