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

📄 demounit.pas

📁 使用SMSControl串口收发短信 - 特别提示!!由于本控件使用了微软公司的COMM32.OCX
💻 PAS
字号:
unit Demounit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleCtrls, TransoftSMSControl_TLB;

type
  TfrmDemo = class(TForm)
    SMS: TSMS;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    txtCenterNo: TEdit;
    cboMobileType: TComboBox;
    Label3: TLabel;
    Label4: TLabel;
    cboRate: TComboBox;
    cboSMSPort: TComboBox;
    chkAutoRec: TCheckBox;
    cmdConnect: TButton;
    cmdDisConnect: TButton;
    GroupBox2: TGroupBox;
    Label5: TLabel;
    Label6: TLabel;
    txtMobileNo: TEdit;
    txtmsg: TMemo;
    cmdSend: TButton;
    chkChinese: TCheckBox;
    GroupBox3: TGroupBox;
    txtrec: TMemo;
    procedure cmdConnectClick(Sender: TObject);
    procedure cmdDisConnectClick(Sender: TObject);
    procedure cmdSendClick(Sender: TObject);
    procedure SMSMsgReceived(ASender: TObject; const MsgSender,
      Msg: WideString; ArrivedTime: TDateTime);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmDemo: TfrmDemo;

implementation

{$R *.dfm}


procedure TfrmDemo.cmdConnectClick(Sender: TObject);
begin

    If chkAutoRec.Checked  = true Then   //判断是否自动接收
        SMS.AutoReceive := True
    Else
        SMS.AutoReceive := False;


    if cboMobileType.Text='标准手机' then
        SMS.MobileType :=0
    else if cboMobileType.Text='Wavecom模块'  then
        SMS.MobileType :=1
    else if cboMobileType.Text='Nokia手机'    then
        SMS.MobileType :=2
    else
        SMS.MobileType :=3;

//    SMS.CommPort := 2;
//    SMS.CommPort :=cboSMSPort.Text;


    if cboSMSPort.Text='1' then
          SMS.CommPort := 1
    else if cboSMSPort.Text='2'  then
          SMS.CommPort := 2
    else if cboSMSPort.Text='3'    then
          SMS.CommPort := 3
    else if cboSMSPort.Text='4'    then
          SMS.CommPort := 4
    else if cboSMSPort.Text='5'    then
          SMS.CommPort := 5;


    SMS.CenterNo := txtCenterNo.Text;
    SMS.Settings := cboRate.Text;

    //打开与手机的通讯
    If SMS.CommOpen = 0 Then
      ShowMessage('连接成功!')
    Else
      ShowMessage('连接失败!');

end;

procedure TfrmDemo.cmdDisConnectClick(Sender: TObject);
begin
  SMS.CommClose();
  ShowMessage('断开成功!');
end;

procedure TfrmDemo.cmdSendClick(Sender: TObject);
begin
  if chkChinese.Checked =true then
    begin
      if SMS.SendMsg(txtMobileNo.Text,txtMsg.Text ,true,false) = 0 then
        ShowMessage('发送成功!')
      else
        ShowMessage('发送失败!');
    end
  else
    begin
      if SMS.SendMsg(txtMobileNo.Text,txtMsg.Text ,false,false) = 0 then
          ShowMessage('发送成功!')
      else
         ShowMessage('发送失败!');
    end;

end;

procedure TfrmDemo.SMSMsgReceived(ASender: TObject; const MsgSender,
  Msg: WideString; ArrivedTime: TDateTime);
begin
  txtRec.text  :=  MsgSender + ':' + Msg;
end;

end.

⌨️ 快捷键说明

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