This sample application uses a DDE link to send data to a DDE server and optionally receive notification updates. The server program, shown in the class DDETopic example, runs in a second instance of dBASE Plus. For a demonstration of multiple-client DDE interaction, create and run another form using this same code, but change the DDE topic from "TEST" to any other name. At the same time, try linking another DDE client to the dBASE Plus server program using some other Windows program, such as Microsoft Word (code for a Word 95 macro to do just that appears at the bottom of this topic).

** END HEADER -- do not remove this line

//

// Generated on 02/24/00

//

parameter bModal

local f

f = new stockclientForm()

if (bModal)

   f.mdi = false // ensure not MDI 

   f.readModal() 

else

   f.open() 

endif

class stockclientForm of FORM

with (this) 

   onOpen = class::FORM_ONOPEN 

   onClose = class::FORM_ONCLOSE 

   scaleFontBold = false 

   height = 6 

   left = 4 

   top = 2 

   width = 42 

   text = "Stock Client 2000" 

   autoCenter = true 

   mdi = false 

endwith 

this.NOTIFYTEXT = new TEXT(this) 

with (this.NOTIFYTEXT) 

   height = 1 

   left = 2 

   top = 2 

   width = 38 

   border = true 

   colorNormal = "BtnText" 

   fontSize = 8 

   text = "Welcome to Stock Client 2000" 

   borderStyle = 7 // Client 

endwith 

this.SHARES = new SPINBOX(this) 

with (this.SHARES) 

   height = 1 

   left = 2 

   top = 4 

   width = 12 

   picture = "99999" 

   step = 10 

   rangeMax = 10000 

   rangeMin = 1 

   fontSize = 8 

   value = 10 

   rangeRequired = true 

   borderStyle = 7 // Client 

endwith 

this.BUYBUTTON = new PUSHBUTTON(this) 

with (this.BUYBUTTON) 

   onClick = class::BUYBUTTON_ONCLICK 

   height = 1 

   left = 18 

   top = 4 

   width = 10 

   text = "&Buy" 

   fontSize = 8 

   group = true 

   value = false 

endwith 

this.SELLBUTTON = new PUSHBUTTON(this) 

with (this.SELLBUTTON) 

   onClick = class::SELLBUTTON_ONCLICK 

   height = 1 

   left = 30 

   top = 4 

   width = 10 

   text = "&Sell" 

   fontSize = 8 

   group = true 

   value = false 

endwith 

this.NOTIFYBUYCHECKBOX = new CHECKBOX(this) 

with (this.NOTIFYBUYCHECKBOX) 

   onChange = class::NOTIFYBUYCHECKBOX_ONCHANGE 

   height = 0.8636 

   left = 2 

   top = 1 

   width = 16 

   text = "Notify on Buy" 

   colorNormal = "WindowText/BtnFace" 

   fontSize = 8 

   value = false 

   group = true 

endwith 

this.NOTIFYSELLCHECKBOX = new CHECKBOX(this) 

with (this.NOTIFYSELLCHECKBOX) 

   onChange = class::NOTIFYSELLCHECKBOX_ONCHANGE 

   height = 0.8636 

   left = 24 

   top = 1 

   width = 16 

   text = "Notify on Sell" 

   colorNormal = "WindowText/BtnFace" 

   fontSize = 8 

   value = false 

   group = true 

endwith 

 

function BUYBUTTON_onClick 

   form.ddeClientObj.poke("Buy", "" + form.shares.value) 

  return 

 

function form_onClose 

   form.ddeClientObj.terminate() 

   form.ddeClientObj.release() // Destroys parent reference to form 

 return 

 

function form_onOpen 

   this.ddeClientObj = new StockDDELink() 

   with this.ddeClientObj 

      if initiate("STOCKSERVER", "TEST") 

         parent = this 

         timeout = 2000 

         msgbox("Connecting to " + server ; 

         + ". Account holder: " + topic ; 

         + ". Current holdings: " + peek("Buy"),; 

         "Stock Client 2000") 

      else 

         msgbox("Could not connect to StockServer", ; 

         "Connection failed", 16) 

         form.close() 

      endif 

endwith 

 

function NOTIFYBUYCHECKBOX_onChange 

   if this.value 

      form.ddeClientObj.advise("Buy") 

   else 

      form.ddeClientObj.unAdvise( "Buy" ) 

   endif 

return 

 

function NOTIFYSELLCHECKBOX_onChange 

   if this.value 

      form.ddeClientObj.advise("Sell") 

   else 

      form.ddeClientObj.unAdvise("Sell") 

   endif 

return 

 

function SELLBUTTON_onClick 

   form.ddeClientObj.poke("Sell", "" + form.shares.value) 

return 

 

endclass

 

 

class StockDDELink of DDELink

this.parent = null 

 

function onNewValue(item, value) 

   this.parent.notifyText.text := "Notified of changes in: " + item + ; 

   " now: " + value 

endclass

This Word for Windows 95 macro also lets you communicate with the dBASE Plus DDE stock server program described in the class DDETopic example. You can use this macro from within Word at the same time as you use the dBASE Plus DDE client application described above to communicate with the dBASE Plus server running in a separate instance.

‘Word 95 macro to communicate with dBASE Plus Stock Server dde sample

Sub MAIN

DDETerminateAll 

channel = DDEInitiate("STOCKSERVER", "TEST") 

DDEPoke channel, "sell", "150" 

DDETerminate channel 

End Sub