4th Dimension as DDE Server

4D - Documentation   Français   English   German   DDE_Tools, Contents   DDE_Tools, Index   Back   Previous   Next

version 6.0


4D's multi-tasking structure requires that the DDE server runs in a specific process, so DDE_Tools provides the additional DDE_SERVER command, which executes DDE commands sent by other applications. Such commands are then executed within the process that called the DDE_SERVER command.

Examples of the DDE server process are provided in the DDE_SERVER command description.

From another application, you can import and set the contents of 4D fields as well as process and interprocess variables.

Creating a Customized Mailing in Microsoft Word

Assume that we have a 4D database named "Contacts.4DB" containing personal information on people in a [Contacts] table. We open this database. Then, in User environment, we select someone to write to by double-clicking that person's record.

In this case, the DDE_SERVER command call can be executed in the form method (cf. Example 2 of the DDE_SERVER command description).

We launch Microsoft Word and draft a letter. At the point at which to write the name of the addressee, we insert a field by choosing Insert field from the Word Insert menu. We then enter the following formula:

{DDE 4D Contacts.4DB [Contacts]Name}

We repeat this procedure for the other fields we want to include in the document, such as first name, address, zip code, etc.

If the title of a field consists of two words separated by a space, it must be within double chevrons, for example: «[Contacts]Zip Code»

Note: To display the contents of a process or interprocess variable, replace the field's title with the name of the variable.

Sending Data to 4th Dimension

Assume that we have an Excel spreadsheet that calculates employee payroll, and that employee tables are managed by 4th Dimension.

In 4th Dimension User environment, we opened the "DatabaseDDE.4db" file. We have the "Dupont" record in User environment.

As in the previous example, the DDE_SERVER command call can be executed in the form method (cf. Example 2 of the DDE_SERVER command description).

Excel processes a typical calculation sheet to determine the amount of the paycheck. A simple macro allows you to calculate the net salary and to send the value to the record. For example, this macro could be:

   Sub CalculateSalary ()
      Channel = DDEInitiate ("4D"; "DatabaseDDE.4DB")
      Cells(10; 5) .Formula = DDERequest (Channel; "[Contacts]GrossSalary")
      Set NetSalary = Cells(5; 5)
      DDEPoke Channel; "[Contacts]Netsalary"; NetSalary
      DDETerminate Channel
   End Sub

The first part of our procedure reads the gross salary entered in the current record and imports it to the cell (10; 5):

   Sub CalculateSalary()
         `Initiate communication with 4D
      Channel = DDEInitiate ("4D"; "DatabaseDDE.4DB")
         `Get the value of the GrossSalary field from 4D
      Cells(10;5).Formula = DDERequest(Channel; "[Contacts]GrossSalary")

The second part recovers the amount of net salary calculated in cell (5; 5) and exports it to the NetSalary field of our current record:

      Set NetSalary = Cells(5;5)
      DDEPoke Channel; "[Employees]NetSalary"; NetSalary
         `Communication may be interrupted
      DDETerminate Channel
   End Sub

Executing 4th Dimension Commands

4D methods can be executed from another application, provided that the application has opened a DDE connection with 4th Dimension.

In this case, you must create a process containing a method that will periodically call the DDE_Server command, as provided in example 1 of the DDE_SERVER command description.

Let us assume that a 4D database contains employee records and a project method that calculates payrolls and stores the result in the <>Result interprocess variable:

MPayroll method

   ALL RECORDS([Employees])
   <>Result:=Sum([Employees]Salary)

This method can now be launched from Excel using the following macro:

   Sub CalculatePayroll()
      Channel = DDEInitiate("4D"; "DatabaseDDE.4DB")
      DDEExecute Channel; "[MPayroll]"
      Cells(8; 5).Formula = DDERequest (Channel; "<>Result")
      DDETerminate Channel
   End Sub

When 4D receives the order from Excel to calculate the payroll, it puts this command in a buffer and waits for the launching of a 4D DDE_SERVER command. When this command is called, 4D executes the command received in the process that called DDE_SERVER, then it validates the operation with the calling operation.

Note: If you failed to install the process that periodically calls the DDE_SERVER command, not only will the issued commands not be executed by 4D, but also, the application that launched the command will continue to expect a response from 4D.

See Also

4th Dimension as DDE Client, DDE_SERVER.


4D - Documentation   Français   English   German   DDE_Tools, Contents   DDE_Tools, Index   Back   Previous   Next