荔园在线
荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀
[回到开始]
[上一篇][下一篇]
发信人: baty (新一代懒人), 信区: Database
标 题: powbuild开发DDE
发信站: BBS 荔园晨风站 (Sat Mar 24 10:30:15 2001), 转信
【 以下文字转载自 baty 的信箱 】
【 原文由 baty.bbs@argo.zsu.edu.cn 所发表 】
发信人: Luqi.bbs@bbs.eme.gliet.edu.cn (今天心情好 ^o~), 信区: Database
标 题: powbuild开发DDE
发信站: 漓江夜话BBS (Fri Apr 9 02:14:43 1999)
转信站: argo!news.zsu.edu.cn!EME-BBS
Origin: 202.193.66.51
摘 要: PB 5.0 具 备 快 速 开 发DDE 服 务 器 应 用
程 序 和DDE 客 户 应 用 程 序 的 功 能, 只 须 掌 握 少
量 几 个 关 于DDE 的 系 统 函 数 和 窗 口 事 件 便 可 以
了。
---- 关 键 字:DDE( 动 态 数 据 交 换,Dynamic Data
Exchange),DDE 服 务 器 应 用 程 序(DDE Server
Application),DDE 客 户 应 用 程 序(DDE Client
Application), 冷 链 接(Cold Link), 温 链 接(Warm Link),
热 链 接(Hot Link).
---- 在WINDOWS 环 境 中, 可 以 同 时 运 行 多 道 应 用
程 序,DDE 是 这 些 应 用 程 序 之 间 进 行 数 据 交 换
的 方 便 方 法。 提 供 数 据 的 应 用 程 序 叫 做DDE 服
务 器 应 用 程 序, 接 收 数 据 的 应 用 程 序 叫 做 客
户 应 用 程 序, 下 面 分 别 简 称 为 服 务 器 和 客
户。DDE 包 括 三 种 链 接 方 式,(1) 冷 链 接,(2) 温 链
接,(3) 热 链 接。 下 面 分 三 种 情 况 分 述。
---- ( 一) 冷 链 接。
---- 在 服 务 器 和 客 户 之 间 只 有 单 个 命 令 时 使
用。
---- 服 务 器 端 的 编 程:
---- 在 这 种 方 式 下, 服 务 器 不 能 主 动 地 通 知
客 户 自 己 的 数 据 变 化, 只 能 被 动 地 在 被 触 发
Rem-oteExec,RemoteRequest,RemoteSend 事 件 之 后 在 这
些 事 件 的Script 中 对 客 户 进 行 回 应。 不 能 在 其
它 地 方 调 用DDE 函 数 来 主 动 地 与 客 户 联 络。 不
可 能 触 发 热 链 接 的 事 件RemoteHotLinkStart,
RemoteHotL-inkStop, 当 然 属 于 客 户 的 事
件HotLinkAlarm 也 不 可 能 触 发。
---- (1) 在 某 个 窗 口 的OPEN 事 件 或 其 它 的 事 件
中 调 用StartServerDDE 函 数 来 指 定 此 应 用 程 序 充
当 服 务 器, 该 窗 口 称 为 服 务 器 窗 口。
---- (2) 在 服 务 器 窗 口 的RemoteExec 事 件 中 调
用GetCommandDDEOrigin,GetCommandDDE 函 数 来 获 取 客
户 发 来 的 命 令 及 命 令 源 , 调 用RespondRemote 函
数 来 表 示 命 令 可 否 接 受, 并 对 命 令 进 行 处
理。 该 事 件 是 由 客 户 调 用 ExecRemote 函 数 触 发。
---- (3) 在 服 务 器 窗 口 的RemoteSend 事 件 中 调
用GetDataDDEOrigin,GetDataDDE 函 数 来 获 取 客 户 发
来 的 数 据 及 数 据 源, 调 用RespondRemote 函 数 来 表
示 数 据 可 否 接 受, 并 对 数 据 进 行 处 理。 该 事
件 由 客 户 端 调 用SetRemote 函 数 触 发。
---- (4) 在 服 务 器 窗 口 的RemoteRequest 事 件 中 调
用SetDataDDE 函 数 来 向 客 户 发 送 数 据, 并 调 用
RespondRemote 函 数 来 通 知 客 户 是 否 应 允 这 个 请
求。
---- (5) 在 想 结 束DDE 时 调 用 StopServerDDE 函 数 中
止。
---- 客 户 端 的 编 程:
---- 在 这 种 方 式 下, 客 户 端 只 能 调 用
ExecRemote,GetRemote,SetRemote 三 个 函 数 分 别 来 向
服 务 器 发 送 命 令, 请 求 数 据, 发 送 数 据, 不 会
有
RemoteExec,RemoteSend,RemoteRequest,RemoteHot-LinkStop,
RemoteHotLinkStart,HotLinkAlarm
等 任 何DDE 事 件 被 触 发。 在 这 种 方 式 下, 因 为
通 讯 的 双 方 没 有 建 立 通 道, 客 户 在 做 出 通 讯
请 求 后WINDOWS 将 轮 流 查 询 所 有 打 开 了 的 应 用,
直 到 得 到 回 应 为 止, 故 这 种 方 式 的 效 率 较
低。
---- 注 意:PowerBuilder 的Application 对 象 的 属
性DDETimeOut 决 定 了 做 为 客 户 的 应 用 程 序 向 服
务 器 请 求 回 应 的 最 大 等 待 时 间。
---- ( 二) 温 链 接。
---- 在 服 务 器 和 客 户 之 间 不 只 有 单 个 命 令 时
使 用。 服 务 器 端 的 编 程: 完 全 和 冷 链 接 一 样。
---- 客 户 端 的 编 程:
---- 大 致 和 冷 链 接 一 样, 具 体 区 别 如 下:
---- (1) 先 调 用OpenChannel 函 数 打 开 通 道, 再 开
始 调 用 上 面 所 说 的 那 三 个 函 数 与 服 务 器 通
讯。
---- (2) 通 讯 完 之 后 调 用CloseChannel 关 闭 通 道。
(
---- 3) 调 用ExecRemote,SetRemote,GetRemote 函 数 时 使
用 温 链 接 的 语 法 格 式。
---- (4) 因 为 打 开 了 专 门 的 通 道, 故WINDOWS 不 必
轮 流 查 询 所 有 打 开 的 应 用 程 序, 效 率 会 比 冷
链 接 高。
---- ( 三) 热 链 接。
---- 在 服 务 器 端 的 数 据 有 变 化 时 服 务 器 主 动
地 通 知 客 户 时 使 用。
---- 服 务 器 端 的 编 程:
---- (1) 最 先 调 用StartServerDDE, 结 束 时 调
用StopServerDDE.
---- (2) 在 数 据 发 生 变 化 时 调 用SetDataDDE 函 数
通 知 客 户, 这 将 触 发 客 户 端 的HotLinkAlarm 事
件。
---- (3) 不 要 在 其 它 的 事 件 中 编 程, 也 不 要 再
调 用 其 它 的 函 数。
---- 客 户 端 的 编 程:
---- (1) 先 调 用StartHotLink 函 数 建 立 热 链 接, 最
后 调 用StopHotLink 中 止。
---- (2) 在 建 立 热 链 接 地 窗 口 的HotLinkAlarm 事 件
中 调 用GetDataDDEOrigin,GetDataDDE 函 数 来 获 得 发 送
来 的 数 据 和 数 据 的 源, 并 对 收 到 的 数 据 进 行
处 理。 再 调 用RespondRemote 回 答 是 否 接 受 。
---- (3) 不 要 在 其 它 的 事 件 中 编 程, 也 不 要 再
调 用 其 它 的 函 数。
---- ( 四) 一 个 三 种 方 式 都 可 进 行 的 例 子
---- 这 个 例 子 在WINDOW95,PB 5 环 境 下 调 试 通 过,
你 可 以 同 时 运 行DDESERVER.EXE 和 DDECLIENT.EXE 两 个
应 用, 前 者 为 服 务 器, 后 者 为 客 户, 在 客 户 端
可 以 任 意 地 建 立 一 种 链 接, 并 与 服 务 器 交 换
数 据。 具 体 过 程 如 下:
---- (1) 进 入PB5.0 开 发 环 境, 建 立 一 个 名 字 叫
ddeserver.pbl 的 新PBL 库 文 件。
---- (2) 在 刚 建 立 的PBL 中 建 立 一 个 名 字
叫ddeserver 的Application 对 象。
---- (3) 按 下 面 的 界 面 建 立 一 个 新 的 窗 口。
---- (4) 它 是 名 字 叫sle_Name 的 单 行 编 辑 文 本
框。
---- (5) 它 是 名 字 叫sle_Sex 的 单 行 编 辑 文 本 框。
---- (6) 它 是 名 字 叫st_LinkType 的 静 态 文 本 框。
---- (7) 它 是 名 字 叫st_Status 的 静 态 文 本 框。
---- (8) 它 是 名 字 叫cb_Close 的 按 钮。
---- (9) 把 新 建 的 窗 口 以 名 字 w_DDEServer 存 盘。
---- (10) 在ddeserver Application 对 象 的OPEN 事
件Script 中 写 入 语 句:Open(w_DDEServer)
---- (11) 为 窗 口w_DDEServer 定 义 实 例 变 量:
Protected:
String is_NeedType=name' //name'
//ex'
String is_LinkType=oldLink'//oldLink'
//armLink'
//otLink'
---- (12) 为 窗 口w_DDEServer 的OPEN 事 件 Script 写 入
下 面 的 程 序:
//============================================================
// The Window w_DDEServer Open Event
// Start DDE Server
//============================================================
Integer li_Temp
//Start This Application As A DDE Server,In This Window
st_Status.Text='Start DDE Server ...... !'
li_Temp=StartServerDDE(w_DDEServer,
'MySampleDDEServer','StudentInformation',&
'StudentName','StudentSex')
//The ApplicationName IS 'MySampleDDEServer'
//The Topic IS 'StudentInformation'
//The Item Has TWO,'StudentName' And 'StudentSex'
If li_Temp=1 Then
st_Status.Text='Start DDE Server Successfully !'
Else
st_Status.Text='Start DDE Server Failed !'
MessageBox(DDEServer.DisplayName,&
'Start DDE Server Failed ,Cannot Continue !'
,&
StopSign!&
)
Halt Close
End If
st_Status.Text='Ready'
---- (13) 为 窗 口w_DDEServer 的CLOSE 事 件 Script 写 入
下 面 的 程 序:
//==========================================================
// The Window w_DDEServer Close Event
// Close DDE Server
//==========================================================
Integer li_Temp
li_Temp=StopServerDDE(w_DDEServer,'MySampleDDEServer',&
'StudentInformation')
If li_Temp<>1 Then
Beep(100)
End If
---- (14) 为 窗 口w_DDEServer 的RemoteRequest 事 件
Script 写 入 下 面 的 程 序:
//==========================================================
// The Window w_DDEServer RemoteRequest Event
// Send Data To The DDE Client
//==========================================================
Integer li_Temp
st_Status.Text='DDE Client Requesting'
If is_NeedType='Name' Then
//Name
li_Temp=SetDataDDE(sle_Name.Text)
If li_Temp=1 Then
st_Status.Text='Send Name Data Ok !'
li_Temp=RespondRemote(True)
Else
st_Status.Text='Send Name Data Error !'
li_Temp=RespondRemote(False)
End If
Else//Sex
li_Temp=SetDataDDE(sle_Sex.Text)
If li_Temp=1 Then
st_Status.Text='Send Sex Data Ok !'
li_Temp=RespondRemote(True)
Else
st_Status.Text='Send Sex Data Error !'
li_Temp=RespondRemote(False)
End If
End If
---- (15) 为 窗 口w_DDEServer 的RemoteSend 事 件 Script
写 入 下 面 的 程 序:
//==========================================================
// The Window w_DDEServer RemoteSend Event
// Get Data Which Sent From The DDE Client
//==========================================================
Integer li_Temp
String ls_AppName,ls_TopicName,ls_ItemName
String ls_StudentName,ls_StudentSex
st_Status.Text='DDE Client Sending'
//Get The Data Origin
li_Temp=GetDataDDEOrigin
(ls_AppName,ls_TopicName,ls_ItemName)
If li_Temp=1 Then
If ls_AppName='MySampleDDEServer' And &
ls_TopicName='StudentInformation' And &
ls_ItemName='StudentName' Then
//Get The Name
li_Temp=GetDataDDE(ls_StudentName)
If li_Temp=1 Then
li_Temp=RespondRemote(True)
sle_Name.Text=ls_StudentName
Else
//Error
li_Temp=RespondRemote(False)
st_Status.Text='Get Data Error !'
End If
Else
If ls_AppName='MySampleDDEServer' And &
ls_TopicName='StudentInformation'
And &
ls_ItemName='StudentSex' Then
//Get The Sex
li_Temp=GetDataDDE(ls_StudentSex)
IF li_Temp=1 Then
li_Temp=RespondRemote(True)
sle_Sex.Text=ls_StudentSex
Else
//Error
st_Status.Text='Get Data
Error !'
li_Temp=RespondRemote(False)
End If
Else
//Other DDE Item
li_Temp=RespondRemote(False)
st_Status.Text='Other DDE Item'
End If
End If
Else
st_Status.Text='Get DDE Origin Error !'
End If
(16) 为 窗 口w_DDEServer 的RemoteExec 事 件 Script 写 入
下 面 的 程 序:
//==========================================================
// The Window w_DDEServer RemoteExec Event
// Get Command Which Sent From The DDE Client And
Process
//==========================================================
Integer li_Temp
String ls_Command,ls_AppName
st_Status.Text='DDE Client Sent Command'
//Get The Command Origin
li_Temp=GetCommandDDEOrigin(ls_AppName)
If li_Temp=1 Then
If ls_AppName='MySampleDDEServer' Then
//Get The Command
li_Temp=GetCommandDDE(ls_Command)
If li_Temp=1 Then
li_Temp=RespondRemote(True)
//Process The Command
CHOOSE CASE ls_Command
CASE 'BeginColdLink'
is_LinkType='ColdLink'
st_LinkStatus.Text='Cold Link'
st_Status.Text='Begin Cold Link'
CASE 'BeginWarmLink'
is_LinkType='WarmLink'
st_LinkStatus.Text='Warm Link'
st_Status.Text='Begin Warm Link'
CASE 'ClearTheName'
sle_Name.Text=''
st_Status.Text='Cleared The Name'
CASE 'ClearTheSex'
sle_Sex.Text=''
st_Status.Text='Cleared The Sex'
CASE 'Name'
is_NeedType='Name'
st_Status.Text='Need The Name'
CASE 'Sex'
is_NeedType='Sex'
st_Status.Text='Need The
Sex'
CASE ELSE
st_Status.Text='Other Command'
END CHOOSE
Else
//Error
li_Temp=RespondRemote(False)
st_Status.Text='Get Data Error !'
End If
Else
//Other App
li_Temp=RespondRemote(False)
st_Status.Text='Other Application Command'
End If
Else
st_Status.Text='Get DDE Command Origin Error !'
End If
---- (17) 为 窗 口w_DDEServer 的RemoteHotLinkStart 事 件
Script 写 入 下 面 的 程 序:
//==========================================================
// The Window w_DDEServer RemoteHotLinkStart Event
// Know The Link Type Is HotLink
//==========================================================
is_LinkType='HotLink'
st_LinkStatus.Text='Hot Link'
st_Status.Text='Started Hot Link'
---- (18) 为 窗 口w_DDEServer 的RemoteHotLinkStop 事 件
Script 写 入 下 面 的 程 序:
//==========================================================
// The Window w_DDEServer RemoteHotLinkStop Event
// Know The Hot Link Stopped
//==========================================================
st_Status.Text='Stopped Hot Link'
---- (19) 进 入sle_Name 的script 画 屏, 定 义 用 户 事
件, 名 字ue_KeyUp,EventID 为
---- pbm_KeyUp
---- (20) 在sle_Name 的 ue_KeyUp 事 件 的Script 中 写 入
下 面 的 程 序:
//==========================================================
// The Control sle_Name us_KeyUp Event
// Send Data To Client When HotLink
//==========================================================
Integer li_Temp
If is_LinkType='HotLink' Then
li_Temp=SetDataDDE(This.Text,'MySampleDDEServer',&
'StudentInformation','StudentName')
If li_Temp=1 Then
st_Status.Text='Set DDE Data Name
Successfully !'
Else
st_Status.Text='Set DDE Data Name Failed !'
End If
End If
---- (21) 进 入sle_Sex 的script 画 屏, 定 义 用 户 事
件, 名 字ue_KeyUp,EventID 为
---- pbm_KeyUp
---- (22) 在sle_Sex 的 ue_KeyUp 事 件 的Script 中 写 入
下 面 的 程 序:
//==========================================================
// The Control sle_Sex us_KeyUp Event
// Send Data To Client When HotLink
//==========================================================
Integer li_Temp
If is_LinkType='HotLink' Then
li_Temp=SetDataDDE(This.Text,'MySampleDDEServer',&
'StudentInformation','StudentSex')
If li_Temp=1 Then
st_Status.Text='Set DDE Data Sex
Successfully !'
Else
st_Status.Text='Set DDE Data Sex Failed !'
End If
End If
---- (23) 在sle_Sex 的 ue_KeyUp 事 件 的Script 中 写 入
下 面 的 程 序:
//==========================================================
// The Control cb_Close Clicked Event
// Close The Window w_DDEServer
//==========================================================
Close(Parent)
---- (24) 建 立 一 个 新 的Project, 名 字 ddeserver, 并
生 成EXE 文 件,ddeserver.exe.
---- (25) 用 类 似 的 方 法 建 立PBL 库
ddeclient.pbl,ddeclient Application 对 象,w_DDEClient
窗 口,ddeclient 工 程 对 象 Project,ddeclient.exe 界
面 如 下:
//==========================================================
//The Control Name List:
//==========================================================
SingleLinkEdit: sle_Name sle_Sex
RadioButton: rb_1 rb_2 rb_3
CommandButton: cb_1 cb_2 cb_3 cb_4
cb_5 cb_6 cb_7 cb_Close
---- (26) 程 序 如 下:
//============================================================
// The Window w_DDEClient Instance Variables Define
//
//
//============================================================
Protected:
String is_LinkType=扖oldLink'//扖oldLink'
//扺armLink'
//扝otLink'
String is_NeedType=扤ame' //扤ame'
//扴ex'
Long il_ChannelHandle //Used For WarmLink Channel
Handle
//============================================================
// The Window w_DDEClient HotLinkAlarm Event
// Get Data Sent Form The DDE Sever
//
//============================================================
Integer li_Temp
String ls_AppName,ls_TopicName,ls_ItemName
String ls_Name,ls_Sex//The Get Data From The DDE Server
Beep(300)
li_Temp=GetDataDDEOrigin(ls_AppName,ls_TopicName,
ls_ItemName)
If li_Temp=1 Then
If ls_AppName='MySampleDDEServer' And &
ls_TopicName='StudentInformation' And &
ls_ItemName='StudentName' Then
li_Temp=GetDataDDE(ls_Name)
If li_Temp=1 Then
sle_Name.Text=ls_Name
Else
st_Status.Text='Get DDE Data
Failed !'
End If
Else
If ls_AppName='MySampleDDEServer' And &
ls_TopicName='StudentInformation'
And &
ls_ItemName='StudentSex' Then
li_Temp=GetDataDDE(ls_Sex)
If li_Temp=1 Then
sle_Sex.Text=ls_Sex
Else
st_Status.Text='Get DDE Data Failed
!'
End If
Else
st_Status.Text='Else Item Changes !'
End If
End If
Else
st_Status.Text='Get DDE Origin Failed !'
End If
//=========================================================
// The Control cb_7 Clicked Event
// Send Sex Data
// Send Sex Data To The DDE Server
//==========================================================
Integer li_Temp
String ls_Sex
SetPointer(HourGlass!)
ls_Sex=sle_Sex.Text
If is_LinkType='ColdLink' Then
li_Temp=SetRemote('StudentSex',ls_Sex,&
'MySampleDDEServer','StudentInformation')
If li_Temp=1 Then
st_Status.Text='Send Data To Server
Successfully !'
Else
st_Status.Text='Send Data To Server Failed
!'
End If
Else
li_Temp=SetRemote('StudentSex',ls_Sex,&
il_ChannelHandle)
If li_Temp=1 Then
st_Status.Text='Send Data To Server
Successfully !'
Else
st_Status.Text='Send Data To Server Failed
!'
End If
End If
SetPointer(Arrow!)
//===========================================================
// The Control cb_6 Clicked Event
// Send Sex Command
// Send Sex Command To The DDE Server
//===========================================================
Integer li_Temp
String ls_Command
If is_NeedType='Sex' Then
Return 1
End If
SetPointer(HourGlass!)
ls_Command='Sex'
If is_LinkType='ColdLink' Then
li_Temp=ExecRemote(ls_Command,'MySampleDDEServer',&
'StudentInformation')
If li_Temp=1 Then
is_NeedType='Sex'
st_Status.Text='Execute Send
'+ls_Command+'Command Successfully !'
Else
st_Status.Text='Execute Send
'+ls_Command+' Command Failed !'
End If
Else
li_Temp=ExecRemote(ls_Command,il_ChannelHandle)
If li_Temp=1 Then
is_NeedType='Sex'
st_Status.Text='Execute Send
'+ls_Command+' Command Successfully !'
Else
st_Status.Text='Execute Send
'+ls_Command+' Command Failed !'
End If
End If
SetPointer(Arrow!)
//==========================================================
// The Control cb_5 Clicked Event
// Send Name Command
// Send Name Command To The DDE Server
//==========================================================
Integer li_Temp
String ls_Command
If is_NeedType='Name' Then
Return 1
End If
SetPointer(HourGlass!)
ls_Command='Name'
If is_LinkType='ColdLink' Then
li_Temp=ExecRemote(ls_Command,'MySampleDDEServer',&
'StudentInformation')
If li_Temp=1 Then
is_NeedType='Name'
st_Status.Text='Execute Send
'+ls_Command+'Command Successfully !'
Else
st_Status.Text='Execute Send
'+ls_Command+' Command Failed !'
End If
Else
li_Temp=ExecRemote(ls_Command,il_ChannelHandle)
If li_Temp=1 Then
is_NeedType='Name'
st_Status.Text='Execute Send
'+ls_Command+' Command Successfully !'
Else
st_Status.Text='Execute Send
'+ls_Command+' Command Failed !'
End If
End If
--
※ 来源:.漓江夜话 bbs.eme.gliet.edu.cn.[FROM: 202.193.66.16]
--
※ 转寄:.逸仙时空 Yat-sen Channel bbs.zsu.edu.cn.[FROM: 210.39.3.50]
--
※ 转载:·BBS 荔园晨风站 bbs.szu.edu.cn·[FROM: 192.168.1.242]
[回到开始]
[上一篇][下一篇]
荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店