⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 Delphi写的SMS试用程序
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, EDISONSMSGWLib_TLB, StdCtrls, ComCtrls, Buttons,
  ExtCtrls;

type
  TForm1 = class(TForm)
    GroupBox3: TGroupBox;
    Label3: TLabel;
    Label5: TLabel;
    ComboBox3: TComboBox;
    ComboBox2: TComboBox;
    GroupBox1: TGroupBox;
    Label4: TLabel;
    Label7: TLabel;
    Memo2: TMemo;
    Panel3: TPanel;
    Label2: TLabel;
    ProgressBar1: TProgressBar;
    Memo1: TMemo;
    Memo3: TMemo;
    StatusBar1: TStatusBar;
    Button3: TButton;
    Label9: TLabel;
    Label1: TLabel;
    ComboBox1: TComboBox;
    Button1: TButton;
    Button2: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure ComboBox1Click(Sender: TObject);
  private
    { Private declarations }
    SysWinNt:Boolean;
    AppPath:String;
  public
    { Public declarations }
    EdisonSmsGw: TEdisonSmsGw;
    procedure EdisonSmsGwOnRecvsms(Sender: TObject; const strPhoneNumber, strSmsContent: WideString; nYear, nMonth, nDay, nHour, nMinute,   nSecond: Smallint);
    procedure EdisonSmsGwOnConnectStatus(Sender: TObject; nStatus: Integer);
    procedure EdisonSmsGwOnSendSmsResult(Sender: TObject; nResult: Smallint; nIndex: Integer; const strPhoneNumber, strSmsContent: WideString);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{******************手机事件 Begin *********************}
procedure TForm1.EdisonSmsGwOnConnectStatus(Sender: TObject; nStatus: Integer);
begin
  label9.Caption:='';
  if nStatus=1 then showmessage('串口打开成功') else  showmessage('串口打开失败!请检查串口号、波特率是否正确;以及是否正确联接了手机。');
  if nStatus=1 then Button1.Enabled:=False;
  Button2.Enabled:=not Button1.Enabled;
  Button3.Enabled:=not Button1.Enabled;
end;

procedure TForm1.EdisonSmsGwOnRecvsms(Sender: TObject; const strPhoneNumber, strSmsContent: WideString; nYear, nMonth, nDay, nHour, nMinute, nSecond: Smallint);
var
  RevDateTime:String;
begin
  RevDateTime:=inttostr(nYear)+'-'+inttostr(nMonth)+'-'+inttostr(nDay)+' '+inttostr(nHour)+':'+inttostr(nMinute)+':'+inttostr(nSecond);
  Memo3.Lines.Add('来自:'+strPhoneNumber+'   接收时间:'+RevDateTime);
  Memo3.Lines.Add('内容:'+strSmsContent);
  Memo3.Lines.Add('---------------------------------------------------------------------------------');
  //if EdisonSmsGw.GetRecvFlag then//查看是否设置为接收允许状态
  {提示音psWhisle}If SysWinNt Then begin Windows.Beep (523,80); Windows.Beep (698,80); Windows.Beep (784,80); Windows.Beep (1046,80); end;
end;


procedure TForm1.EdisonSmsGwOnSendSmsResult(Sender: TObject; nResult: Smallint; nIndex: Integer; const strPhoneNumber, strSmsContent: WideString);
var
  NextNumber:string;
begin
  if nResult=1 then
     Memo1.Lines.Strings[nIndex]:= strPhoneNumber+':成功['+strSmsContent+']'
  else
     Memo1.Lines.Strings[nIndex]:= strPhoneNumber+':失败['+strSmsContent+']';

  {提示音bError}If (SysWinNt=true)and(nResult<>1) Then begin Windows.Beep (100,100); Windows.Beep (50,100); end;

  NextNumber:=Memo1.Lines.Strings[nIndex+1];
  if NextNumber<>'' then
  begin
  {|}  if pos(':',NextNumber)>0 then  NextNumber:=copy(NextNumber,1,pos(':',NextNumber)-1);
  {|}  EdisonSmsGw.SendSms(NextNumber,Memo2.Text,nIndex+1);
  end else
  begin
  {|}  Button3.Enabled:=True;
  {|}  Button3.Caption:='开始发送'
  end;
end;
{******************手机事件 End *********************}





procedure TForm1.FormCreate(Sender: TObject);
var
  VersionInfo : TOSVersionInfo;
begin
  AppPath:=ExtractFilePath(Application.EXEName);
  if copy(AppPath, length(AppPath), 1) <> '\' then AppPath := AppPath + '\';
  VersionInfo.dwOSVersionInfoSize:=SizeOf (VersionInfo);
  GetVersionEx(VersionInfo);
  SysWinNt:=VersionInfo.dwPlatformID=VER_PLATFORM_WIN32_NT;
  Winexec(Pchar('regsvr32.exe SMSControl.ocx -s'),0);
  Button1.Enabled:=True;
  Button2.Enabled:=not Button1.Enabled;
  Button3.Enabled:=not Button1.Enabled;
  EdisonSmsGw                  := TEdisonSmsGw.Create(Form1);
  EdisonSmsGw.Parent           := Form1;
  EdisonSmsGw.Top              := 1;
  EdisonSmsGw.Left             := 470;
  EdisonSmsGw.height           := 10;
  EdisonSmsGw.width            := 10;
  EdisonSmsGw.Tag              := 0;
  EdisonSmsGw.Name             := 'EdisonSmsGw1';
  EdisonSmsGw.OnConnectStatus  := EdisonSmsGwOnConnectStatus; //设备连接返回结果
  EdisonSmsGw.OnRecvsms        := EdisonSmsGwOnRecvsms;       //新短信到达
  EdisonSmsGw.OnSendSmsResult  := EdisonSmsGwOnSendSmsResult  //短信发送返回结果
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  Memo1.Clear;
  Memo2.Clear;
  Memo3.Clear;
  Label9.Caption:='';
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  ComPort:String;
begin
  ComPort:='com'+inttostr(ComboBox2.ItemIndex+1);
  EdisonSmsGw.SetModemType(1); //EdisonSmsGw.SetModemType(ComboBox1.ItemIndex); //0为手机设备, 1为工业GSM Modem
  EdisonSmsGw.ComRate:=strtoint(ComboBox3.Text);
  EdisonSmsGw.SetSendRate(0);    //设置短信发送速度,两条短信发送间的间隔空闲(单位为0.1秒)
  if EdisonSmsGw.ConnectModem(ComPort,EdisonSmsGw.ComRate,0)=1 then label9.Caption:='正在连接设备,请稍候...';
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  EdisonSmsGw.DisconnectModem;
  Button1.Enabled:=True;
  Button2.Enabled:=not Button1.Enabled;
  Button3.Enabled:=not Button1.Enabled;
  Button3.Caption:='开始发送'
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  i:integer;
  mobile:String;
begin
  for i:=0 to memo1.Lines.Count-1 do
  begin
  {|}  if (pos('成功',Memo1.Lines.Strings[i])<=0)and(pos('失败',Memo1.Lines.Strings[i])<=0) then
  {|}  begin
  {|}  {|}  if pos(':',Memo1.Lines.Strings[i])>0 then
  {|}  {|}     mobile:=copy(Memo1.Lines.Strings[i],1,pos(':',Memo1.Lines.Strings[i])-1)
  {|}  {|}  else
  {|}  {|}     mobile:=Memo1.Lines.Strings[i];
  {|}  {|}  EdisonSmsGw.SendSms(mobile,Memo2.Text,i);
  {|}  {|}  Button3.Enabled:=False;
  {|}  {|}  Button3.Caption:='正在发送...';
  {|}  {|}  break;
  {|}  end;
  end;
end;

procedure TForm1.ComboBox1Click(Sender: TObject);
begin
  if(ComboBox1.ItemIndex=0)or(ComboBox1.ItemIndex=1)or(ComboBox1.ItemIndex=2) then
     ComboBox3.ItemIndex:=3
  else
     ComboBox3.ItemIndex:=2;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -