ideString(Memo1.Lines.Text), SpinEdit1.Value); if s='' then Memo1.Lines.Add('发短信失败 no='+Edit1.Text) else Memo1.Lines.Add('发短信号码:'+s); end; //显示OCX控件版本 procedure TForm2.AboutClick(Sender: TObject); begin JD.ShowAboutBox; end; //------------------------------------------------------------------------------ //打开连接端口时触发 procedure TForm2.JDAfterOpen(Sender: TObject); var s: string; i: SmallInt; begin Memo1.Lines.Add('Open: '+JD.Port+' , '+JD.BaudRate); //获取本机号码 for i:=0 to JD.GetComportCount-1 do begin s:=JD.getCNUM(i); //返回本机号码,当为空时,表示未设置本机号码,可用setThisPhoneNo设置 if s<>'' then Memo1.Lines.Add('SIM'+IntToStr(i)+' 本机号码: '+s); end; i:=JD.getCSQValue(SpinEdit1.Value); if (i>=0) then ProgressBar1.Position:=i; end; //关闭连接端口时触发 procedure TForm2.JDAfterClose(Sender: TObject); begin Memo1.Lines.Add('Close'); ProgressBar1.Position:=0; end; //结束响铃时触发,devid是手机盒连接序号,一台计算机可以连接多个手机盒,devid分别为0,1,2... procedure TForm2.JDEndRing(Sender: TObject; devid: Smallint); begin Memo1.Lines.Add(IntToStr(devid)+' End Ring'); end; //电话呼入时,手机响铃,触发此事件。no为来电号码 procedure TForm2.JDRing(Sender: TObject; const no: WideString; index, devid: Smallint); begin Memo1.Lines.Add(IntToStr(devid)+' Ring '+IntToStr(index)+', no='+no); end; //接收到短信时触发,不推荐使用,建议使用OnJDSms事件 //id为短信标识号,可根据id读短信内容 //devid是手机盒连接序号 procedure TForm2.JDSms(Sender: TObject; const id: WideString; devid: Smallint); begin Memo1.Lines.Add('SMS'+IntToStr(devid)+' id='+id); end; { var n: SmallInt; no, t, s: WideString; begin if FileExists('C:\WINDOWS\Media\notify.wav') then sndPlaySound('C:\WINDOWS\Media\notify.wav', SND_ASYNC); //播放声音提示 Memo1.Lines.Add('SMS'+IntToStr(devid)+', id='+id); if id='' then Exit; JD.ReadLongSmsWay:=0; //读超长短信方式,在OnSms事件中,最好设为0,其它时候设为1 n:=JD.ReadSms(id, no, t, s, devid); //按id读短信函数 Memo1.Lines.Add('Read SMS'+IntToStr(devid)+' Count='+IntToStr(n)); if n>0 then begin Memo1.Lines.Add('id='+id+' no='+no+' t='+t); Memo1.Lines.Add(s); end; end; } //接收到短信时触发,推荐使用 //id为短信标识号,no为发送短信号码,t为接收短信时间,s为短信内容 //devid是手机盒连接序号 procedure TForm2.JDJDSms(Sender: TObject; const id, no, t, s: WideString; devid: Smallint); begin if FileExists('C:\WINDOWS\Media\notify.wav') then sndPlaySound('C:\WINDOWS\Media\notify.wav', SND_ASYNC); //播放声音提示 Memo1.Lines.Add('SMS'+IntToStr(devid)+' id='+id+' no='+no+' t='+t); Memo1.Lines.Add(s); end; //测试属性,ExecJDSmsEvent---当为True时,才能执行OnJDSms事件,否则不执行OnJDSms procedure TForm2.SpeedButton1Click(Sender: TObject); begin JD.ExecJDSmsEvent:=not JD.ExecJDSmsEvent; if JD.ExecJDSmsEvent then Memo1.Lines.Add('ExecJDSmsEvent=True') else Memo1.Lines.Add('ExecJDSmsEvent=False'); end; //拨号失败、连接不成功,均触发此事件;str为失败原因 //devid是手机盒连接序号 procedure TForm2.JDNoCarrier(Sender: TObject; const str: WideString; devid: Smallint); begin JD.CloseWaiting; //关闭拨号时的提示窗口 Memo1.Lines.Add(IntToStr(devid)+' '+str); Button10.Enabled:=JD.AllowSendDTMF(SpinEdit1.Value); //判断是否允许使用“通话应答”按钮 end; //设置本机号码 procedure TForm2.Button12Click(Sender: TObject); var s: string; begin if InputQuery('设置本机号码', '请输入本机号码', s) then if JD.setThisPhoneNo(s, SpinEdit1.Value) then if s='' then Memo1.Lines.Add('清除本机号码') else Memo1.Lines.Add('本机号码设置为 '+s); end; //读取SIM卡电话本内容 procedure TForm2.Button13Click(Sender: TObject); var p: SmallInt; str, idx, no, nm: widestring; begin idx:=Edit1.Text; if (idx='') or (idx='0') then begin //返回SIM卡中的所有电话号码,1行1个号码,即号码之间分隔符为回车和换行符 str:=JD.ReadSimBooksAll(SpinEdit1.Value); Memo1.Lines.Add(str); //分析返回内容,提取号码 p:=Pos(#13#10, str); while p>0 do begin //从返回字符串中按行提取电话号码和姓名 //第一个参数为要分析的字符串,即ReadSimBooksAll返回的其中1行内容 //传递回来的参数分别为索引号(存放位置)、号码、姓名 if JD.ExtractSimBooks(Copy(str, 1, p-1), idx, no, nm) then Memo1.Lines.Add(idx+' , '+no+' , '+nm); Delete(str, 1, p+1); p:=Pos(#13#10, str); end; end //按索引号读取SIM卡中的电话号码和姓名,成功时返回True //第一个参数为索引号,传递回来的参数分别为号码、姓名 else if JD.ReadSimBooks(StrToInt(idx), no, nm, SpinEdit1.Value) then Memo1.Lines.Add('SIM'+IntToStr(SpinEdit1.Value)+' : '+idx+' , '+no+' , '+nm); end; //把电话号码存入SIM卡 procedure TForm2.Button14Click(Sender: TObject); var no, nm: string; begin if InputQuery(Button14.Caption, '请输入电话号码:', no) then if InputQuery(Button14.Caption, '请输入姓名:', nm) then //向SIM卡中添加号码,成功时返回True //第一个参数为号码,第二个参数为姓名 //第三个参数为索引号,即指定存放位置;如果为0,自动按顺序存放 if JD.AddSimBooks(no, nm, 0, SpinEdit1.Value) then Memo1.Lines.Add('电话本:'+no+' , '+nm); end; //删除SIM卡中的电话号码 procedure TForm2.Button15Click(Sender: TObject); var str: string; begin if InputQuery(Button15.Caption, '请输入要删除的索引号:', str) then //删除SIM卡中的号码,成功时返回True //第一个参数为索引号(存放位置) if JD.DeleteSimBooks(StrToInt(str), SpinEdit1.Value) then Memo1.Lines.Add('删除电话本:Index='+str); end; end. 示例程序演示界面
|