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. 示例程序演示界面
|