class DDETopic example
The following program creates a DDE service in an instance of dBASE Plus. This server handles information passed to it from multiple DDE clients, including those set up in the dBASE Plus application (using a separate dBASE Plus instance) and Microsoft Word macro shown in the class DDELink example.
set procedure to program(1) additive
_app.ddeServiceName = "STOCKSERVER"
_app.onInitiate = InitStockDDE
_app.framewin.text = "Stock Server 2000"
? "Ready for DDE server requests for:", _app.ddeServiceName
function InitStockDDE(newTopic)
// DDETopic object not in memory, create it
local x
x = new StockDDETopic(newTopic)
? "Initialized server for topic:", newTopic
return x // Must return requested topic
class StockDDETopic(t) of DDETopic(t)
this.adviseList = new AssocArray()
this.value = 100
function onAdvise(item)
? this.topic, "ADVISE on changes in:", item
this.adviseList[ upper(item) ] = null // Create element with dummy value
function onExecute(cmd)
? this.topic, "EXECUTE:", cmd
// This server does not support any commands
function onPeek(item)
? this.topic, "PEEK:", item
return this.value
function onPoke(item /* Buy or Sell */, value /* Shares */ )
? this.topic, "POKE:", item, value
if upper(item) = "SELL"
this.value -= val(value)
elseif upper(item) = "BUY"
this.value += val(value)
endif
// Notify clients if item in adviseList
if this.adviseList.isKey(upper(item))
? this.topic, "NOTIFY change in:", item
this.notify(upper(item)) // Implicitly calls onPeek to get value
endif
? "Value is now:", this.value
function onUnadvise(item)
if this.adviseList.isKey(upper(item))
? this.topic, "cancel ADVISE on changes in:", item
this.adviseList.removeKey(upper(item))
endif
endclass