DDE Client
Version 1.0
Delphi component

 

Vincent LESAUVAGE
26, allée Darius Milhaud - 75019 PARIS - FRANCE
vincentl@club-internet.fr
http://www.mygale.org/04/vincentl

 

This is the component that Borland has not done correctly since Delphi 2.0, and that you can get finally: one DDE component which allow to connect to a data stream such as Excel or Reuter in order to get datas back in real.

DDE unit implements in 2 components (TDDEManager and TDDEClient) the Dynamic Data Exchange protocol for client side. You can use it with all versions of Delphi in 16 or 32 bits.

When 2 applications communicate together using DDE protocol, the one that gives datas is called server, and the other that receives datas is called client. Exchange process between 2 applications is called conversation. It is up to client application to start the conversation.

Datas have adresses (like people). An adress is divided in 3 parts (Service, Topic, Item): Service is the data source, generally the program name; Topic means a group of datas with the same properties; Item is a data in this group. When a client application wish to receive datas from a server application, it sends a request <Service, Topic> to the server which accept or refuse the conversation. Then the client ask a for a precise data with a request <Item>. Client can also ask to the server to notify the client each time the data has a new value.

A client can have many simultaneous conversations with many servers.

 

 

TDDEManager

TDDEManager = class(TComponent)
    Clients: TList;

    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    function PasteLink(var Service, Topic, Item: string): Boolean;
  end;

TClient = class
    DDEClient: TDDEClient;

    constructor Create(DDEC: TDDEClient);
  end;

 

TDDEManager component initializes the DDE protocol for the client application. A client application must have one and one only TDDEManager component. An error EDDEError is raised in case of problem.

The DDE manager saves all conversations in the field Clients, TClient list. Normally you don't have to use it.

The function PasteLink is used to get information about the conversation. A conversation between 2 applications is defined by 2 strings, Service and Topic. Service is usally the program name of the server. Topic is the name of a range of datas with the same properties. Item is the data you can get back.

The destructor deletes all conversations if they are not closed.

 

TDDEClient

TDDEClient = class(TComponent)
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    function OpenConversation: Boolean;
    function CloseConversation: Boolean;

    function RequestData(Item: string; var DataSize: Integer): PChar;
    function AdviseData(Item: string): Boolean;
    function UnadviseData(Item: string): Boolean;
    function Execute(Item: string; Command: string): Boolean;

    property Service: string;
    property Topic: string;
    property Format: Integer;
    property TimeOut: Integer;
    property OnDataChange: TOnDataChange;
  end;

TOnDataChange = procedure(Item: string; const Value: PChar; ValueSize: Integer) of object;

 

The TDDEClient component is the conversation between the client and the server.

To open a conversation, you have to set Service and Topic, then call the function OpenConversation which returns True if the conversion is open. The conversation is added to the list of the DDE manager.

CloseConversation close the conversation and delete it from the list of the DDE manager.

Once the conversation is open, you can get datas back, but set Format and TimeOut before all..

Format indicates to the server in what format it has to send datas (see Windows help for constants CF_xxx, default equals to CF_TEXT or 1).

TimeOut set a delay for the request. After this delay in milliseconds, the function ends. All functions are synchronous: the function gives the control to you after finishing its job.

You can ask for a data one time to the server with the function RequestData en précisant Item, qui désigne cette donnée. Return of RequestData is a pointer on the data which has a size in bytes given by DataSize. You have to free the result with StrDispose.

You can also ask to the serveur to notify the client each time the data has a new value and get back this value, with the function AdviseData, by setting Item. If the server accepts the request, the function returns True. If the method OnDataChange is defined, then it is called each time the data has a new value. The same method OnDataChange can be used to get many different datas: you need to call AdviseData by setting Item for each data you want to get back.

UnadviseData stops the notification for a given Item, and returns True if success.

Execute sends a command in a string to the server, and returns True if success.