ID: Q112047
2.50 2.50a 2.50b WINDOWS kbinterop kbprg
The information in this article applies to:
FoxPro for Windows can be both a dynamic data exchange (DDE) server and a DDE client. FoxPro for Windows ships with DDEDATA.PJX and all the source code. Using this application, and two instances of FoxPro for Windows, one as the client and one as the server, it is easy to demonstrate the value of DDE, as shown below.
NOTE: This article assumes that your machine has sufficient memory to run two instances of FoxPro for Windows.
1. Start FoxPro for Windows and open DDEDATA.PJX from the
FOXPROW\SAMPLE\DDE subdirectory.
2. Build the application.
3. Run DDEDATA.APP. This application sets up this instance of FoxPro for
Windows as a DDE Server.
4. Start another instance of FoxPro for Windows.
5. In order to establish the DDE link, type the following in the instance
of FoxPro for Windows that was just started:
m.chan = ddeinitiate("DDEData","c:\foxprow\tutorial\;TABLE customer")
NOTE: If necessary, "c:\foxprow\tutorial\" should be changed to reflect
the directory where the CUSTOMER.DBF file is located. Technically,
"DDEData" is the service name, and "c:\foxprow\tutorial\;TABLE customer"
is the topic.
The variable m.chan will contain a value representing the DDE channel.
All subsequent DDE commands will refer to this channel.
6. To request some information from the server, type:
m.names=dderequest(m.chan,"FIELDNAMES")
The variable m.names will contain a list of field names from the
CUSTOMER table separated by tabs. DDEDATA.APP is set up to recognize the
item "FIELDNAMES".
Other items it can recognize include "ALL", "DATA", "NEXTROW",
"PREVROW", "FIRSTROW", "LASTROW", and "FIELDCOUNT".
7. To get the next record's data, type:
m.data=dderequest(m.chan,"NEXTROW")
The variable m.data will contain one record's fields separated by tabs.
8. To change the current record, type:
m.confirm = ddepoke(m.chan,"Contact","Jane Doe")
The variable m.confirm will contain a .T. if the action took place or a
.F. if it failed. In this case, DDEDATA.APP would replace the CONTACT
field with "Jane Doe" on the current record.
9. To end the conversation, type:
m.confirm = ddeterminate(m.chan)
The variable m.confirm contains a .T. if the DDE link was terminated
successfully.
Additional features can be added to DDEDATA.APP. In order to do this, you must modify DDEDATA.PRG and then rebuild the application. This application simply institutes a large DO CASE statement in order to respond to different DDE messages. For example, even though DDEDATA.APP enables the DDEExecute service, it doesn't do anything with it. However, if you added
Case sAction = "EXECUTE"
&sData
as part of the DO CASE statement in the cbDataTopic, then when you typed
m.confirm = ddeexecute(m.chan,"wait window 'Hello'")
the instance of FoxPro running DDEDATA.APP would display a wait window with
the text "Hello".
NOTE: The variable m.confirm again reveals if the command succeeded or failed. The "&sData" line is simply using macro substitution. The contents of sData are interpreted by FoxPro as if they had been typed in the Command window.
DDEDATA.APP can be modified to accept and respond to many more requests. It is simply a matter of changing the DO CASE statement to accommodate these new items.
"Developer's Guide," version 2.5, Chapter 12
"Language Reference," version 2.5, pages L3-371, L3-363, L3-366,L3-369, L3-382
Additional reference words: FoxWin 2.50 2.50a 2.50b DDEData KBCategory: kbinterop kbprg KBSubcategory: FxinteropDde
Keywords : FxinteropDde
Version : 2.50 2.50a 2.50b
Platform : WINDOWS
Last Reviewed: May 1, 1996