ddeadvise( ) 函数示例

下面的示例演示如何与 microsoft excel 的 sheetl 工作表建立一个 dde 通道,并用 ddeadvise( ) 函数建立与两个工作表单元 r1c1 和 r1c2 中数据的链接。当两个工作表单元中任意数据发生变化时,执行用户自定义函数 newdata。用户自定义函数测试在 item 和 advise 参数中改变了哪些项,建立什么类型的链接。

public mchannum
mchannum = ddeinitiate('excel', 'sheet1')
if mchannum != -1
= ddeadvise(mchannum, 'r1c1', 'newdata', 1) && 交互式链接
= ddeadvise(mchannum, 'r1c2', 'newdata', 2) && 自动链接
wait window 'enter data in first two cells in excel.'
endif
procedure newdata
parameters channel, action, item, data, format, advise
if action = 'advise'
do case
case item = 'r1c1' && 交互式链接
newvalue = dderequest(channel, item)
? 'r1c1 notify link: ' + newvalue

case item = 'r1c2' && 自动链接
newvalue = data
? 'r1c2 automatic link: ' + newvalue
endcase
else
if action != "terminate"
= ddeterminate(mchannum)
endif
endif