这是我们短信控件的Demo, http://www.sms2008.net
unit uMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, KoSMSXControl_TLB, StdCtrls;
type
TfrmMain = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
cbModemType: TComboBox;
Label2: TLabel;
edtCenterNo: TEdit;
Label3: TLabel;
cbAvailPorts: TComboBox;
btnOpenComm: TButton;
btnCloseComm: TButton;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
GroupBox4: TGroupBox;
Label4: TLabel;
edtPhoneNo: TEdit;
Label5: TLabel;
mmoContent: TMemo;
btnSend: TButton;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
mmoLogs: TMemo;
Label6: TLabel;
KoSMSX1: TKoSMSX;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure btnSendClick(Sender: TObject);
procedure btnOpenCommClick(Sender: TObject);
procedure KoSMSX1MsgReceived(ASender: TObject; const PhoneNo,
Content: WideString; TimeStamp: TDateTime);
procedure KoSMSX1StatusReport(ASender: TObject; StatusCode: Integer;
const PhoneNo, Content: WideString; MessageID: Integer);
procedure KoSMSX1IncomingCall(ASender: TObject;
const IncomePhoneNo: WideString; IncomeTime: TDateTime);
procedure KoSMSX1Connected(Sender: TObject);
procedure KoSMSX1Disconnected(Sender: TObject);
procedure btnCloseCommClick(Sender: TObject);
private
{ Private declarations }
procedure ConnectDevice(Active: Boolean);
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
procedure TfrmMain.FormCreate(Sender: TObject);
var
sPorts: WideString;
begin
Caption := Application.Title;
ConnectDevice(False);
KoSMSX1.EnumComPorts(sPorts);
cbAvailPorts.Items.CommaText := sPorts;
if cbAvailPorts.Items.Count > 0 then
cbAvailPorts.ItemIndex := 0;
end;
procedure TfrmMain.FormDestroy(Sender: TObject);
begin
KoSMSX1.Close;
end;
procedure TfrmMain.btnSendClick(Sender: TObject);
var
sPhoneNo, sContent, sOptions: string;
begin
sOptions := '';
btnSend.Enabled := False;
try
sPhoneNo := edtPhoneNo.Text;
sContent := mmoContent.Text;
if CheckBox1.Checked then // 免提短信
sOptions := sOptions + 'F';
if CheckBox2.Checked then // 状态报告
sOptions := sOptions + 'R';
if KoSMSX1.SendMsg(edtPhoneNo.Text, sContent, 0, sOptions) then
ShowMessage('发送成功!')
else
ShowMessage('发送失败!');
finally
btnSend.Enabled := True;
end;
end;
procedure TfrmMain.btnOpenCommClick(Sender: TObject);
var
s: string;
begin
mmoLogs.Clear;
KoSMSX1.CommName := cbAvailPorts.Text;
KoSMSX1.CenterNo := edtCenterNo.Text;
KoSMSX1.ModemType := cbModemType.ItemIndex;
case KoSMSX1.Open of
0: begin
s := '连接成功';
KoSMSX1.ReadAllMsg;
end;
1: s := '端口无效';
2: s := '端口已被占用';
3: s := '设备没有上电';
4: s := '初始化失败';
5: s := '不支持协议';
end;
ShowMessage(s);
end;
procedure TfrmMain.btnCloseCommClick(Sender: TObject);
begin
KoSMSX1.Close;
end;
procedure TfrmMain.KoSMSX1MsgReceived(ASender: TObject; const PhoneNo,
Content: WideString; TimeStamp: TDateTime);
begin
mmoLogs.Lines.Add('时间:' + DateTimeToStr(TimeStamp));
mmoLogs.Lines.Add('来自:' + PhoneNo);
mmoLogs.Lines.Add('内容:' + Content);
mmoLogs.Lines.Add('=================================');
end;
//状态报告事件
procedure TfrmMain.KoSMSX1StatusReport(ASender: TObject;
StatusCode: Integer; const PhoneNo, Content: WideString;
MessageID: Integer);
var
s: string;
begin
mmoLogs.Lines.Add('接收号码:' + PhoneNo);
mmoLogs.Lines.Add('短信编号:' + IntToStr(MessageID));
mmoLogs.Lines.Add('短信内容:' + Content);
if StatusCode = 0 then
s := '成功'
else
s := '失败';
mmoLogs.Lines.Add('发送结果:' + s);
mmoLogs.Lines.Add('=================================');
end;
procedure TfrmMain.KoSMSX1IncomingCall(ASender: TObject;
const IncomePhoneNo: WideString; IncomeTime: TDateTime);
begin
mmoLogs.Lines.Add('来电时间:' + DateTimeToStr(IncomeTime));
mmoLogs.Lines.Add('来电号码:' + IncomePhoneNo);
mmoLogs.Lines.Add('=================================');
end;
procedure TfrmMain.KoSMSX1Connected(Sender: TObject);
begin
ShowMessage('Connected');
ConnectDevice(True);
end;
procedure TfrmMain.KoSMSX1Disconnected(Sender: TObject);
begin
ShowMessage('Disconnected');
ConnectDevice(False);
end;
procedure TfrmMain.ConnectDevice(Active: Boolean);
begin
btnOpenComm.Enabled := not Active;
btnCloseComm.Enabled := Active;
btnSend.Enabled := Active;
end;
end.
参见: http://www.sms2008.net 有一堆。
下载: http://www.sms2008.net/files/KoSMSGateWay_V2006.rar
通过Outlook收发短信演示: http://www.sms2008.net/files/Outlook_Demo.rar
通过Foxmail收发短信演示: http://www.sms2008.net/files/Foxmail_Demo.rar
现成产品,无需自已再花精力做了。