📄 shortmessage.pas
字号:
unit shortmessage;
interface
uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
Buttons, ExtCtrls, Dialogs,global, ComCtrls;
type
TForm_ShortMessage = class(TForm)
Edit_msg: TMemo;
Timer_sms: TTimer;
GroupBox_msg: TGroupBox;
GroupBox_number: TGroupBox;
Edit_number: TEdit;
Button_handin: TSpeedButton;
Button_search: TSpeedButton;
OKBtn: TButton;
CancelBtn: TButton;
ListView_number: TListView;
GroupBox_action: TGroupBox;
RadioButton_send: TRadioButton;
RadioButton_save: TRadioButton;
RadioButton_copy: TRadioButton;
RadioButton_savesend: TRadioButton;
GroupBox_location: TGroupBox;
RadioButton_simoutbox: TRadioButton;
RadioButton_siminbox: TRadioButton;
RadioButton_flashoutbox: TRadioButton;
RadioButton_flashInbox: TRadioButton;
RadioButton_pc: TRadioButton;
Button_delete: TSpeedButton;
RadioButton_Re: TRadioButton;
RadioButton_Forward: TRadioButton;
RadioButton_Delete: TRadioButton;
RadioButton_savePC: TRadioButton;
procedure FormActivate(Sender: TObject);
procedure Edit_numberChange(Sender: TObject);
procedure Edit_numberKeyPress(Sender: TObject; var Key: Char);
procedure Edit_numberExit(Sender: TObject);
procedure Button_handinClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button_searchClick(Sender: TObject);
procedure Button_deleteClick(Sender: TObject);
procedure Timer_smsTimer(Sender: TObject);
procedure OKBtnClick(Sender: TObject);
procedure Edit_msgChange(Sender: TObject);
private
{ Private declarations }
public
sendnum:string;
sendname:string;
{ Public declarations }
end;
TCharSet=set of char;
var
Form_ShortMessage: TForm_ShortMessage;
NumberSet:TCharSet=['0'..'9','p','#','*','+',#8,#3,#22,#24,#26];//#8=backspace,copy,paste,cut
implementation
uses main, phbsearch;
{$R *.dfm}
procedure TForm_ShortMessage.FormActivate(Sender: TObject);
var temptext1:string;
temptext2:string;
tempitem:TListItem;
begin
RadioButton_PC.Enabled:=false;
RadioButton_flashInbox.Enabled:=false;
RadioButton_flashOutbox.Enabled:=false;
RadioButton_simInbox.Enabled:=false;
RadioButton_simoutbox.Enabled:=false;
RadioButton_flashOutbox.Checked:=true;
RadioButton_flashOutbox.Checked:=false;
if form_main.ListView_shortmessage_main.Selected<>nil then
begin
temptext1:= form_main.ListView_Shortmessage_main.Selected.Caption;
temptext2:= form_main.ListView_Shortmessage_main.Selected.SubItems[1];
if temptext1='PC' then
begin
RadioButton_PC.Enabled:=true;
RadioButton_PC.Checked:=true;
RadioButton_flashInbox.Enabled:=false;
RadioButton_flashOutbox.Enabled:=false;
RadioButton_simInbox.Enabled:=false;
RadioButton_simoutbox.Enabled:=false;
RadioButton_savePC.Enabled:=false;
end;
if temptext1='手机' then
begin
if temptext2='SMS MT' then
begin
RadioButton_PC.Enabled:=false;
RadioButton_flashInbox.Enabled:=true;
RadioButton_flashOutbox.Enabled:=false;
RadioButton_simInbox.Enabled:=false;
RadioButton_simoutbox.Enabled:=false;
RadioButton_flashInbox.Checked:=true;
end;
if (temptext2='STO UNSENT') or (temptext2='STO SENT') then
begin
RadioButton_PC.Enabled:=false;
RadioButton_flashInbox.Enabled:=false;
RadioButton_flashOutbox.Enabled:=true;
RadioButton_simInbox.Enabled:=false;
RadioButton_simoutbox.Enabled:=false;
RadioButton_flashOutbox.Checked:=true;
end;
RadioButton_savePC.Enabled:=true;
end;
if temptext1='SIM' then
begin
if (temptext2='REC UNREAD') or (temptext2='REC READ') then
begin
RadioButton_PC.Enabled:=false;
RadioButton_flashInbox.Enabled:=false;
RadioButton_flashOutbox.Enabled:=false;
RadioButton_simInbox.Enabled:=true;
RadioButton_simoutbox.Enabled:=false;
RadioButton_simInbox.Checked:=true;
end;
if (temptext2='STO UNSENT') or (temptext2='STO SENT') then
begin
RadioButton_PC.Enabled:=false;
RadioButton_flashInbox.Enabled:=false;
RadioButton_flashOutbox.Enabled:=false;
RadioButton_simInbox.Enabled:=false;
RadioButton_simoutbox.Enabled:=true;
RadioButton_simoutbox.Checked:=true;
end;
if (temptext2='UNKNOWN') then
begin
RadioButton_PC.Enabled:=false;
RadioButton_flashInbox.Enabled:=false;
RadioButton_flashOutbox.Enabled:=false;
RadioButton_simInbox.Enabled:=false;
RadioButton_simoutbox.Enabled:=false;
RadioButton_flashOutbox.Checked:=true;
RadioButton_flashOutbox.Checked:=false;
end;
RadioButton_savePC.Enabled:=true;
end;
ListView_number.Clear;
if trim(form_main.ListView_Shortmessage_main.Selected.SubItems[2])<>'' then
begin//加入发送号码
tempitem:=ListView_number.Items.Add;
tempitem.Caption:=form_main.ListView_Shortmessage_main.Selected.SubItems[2];
tempitem.SubItems.Add(form_main.ListView_Shortmessage_main.Selected.SubItems[3]);
end;
edit_msg.Text:=form_main.ListView_Shortmessage_main.Selected.SubItems[5];
end else
begin
GroupBox_msg.Caption:='内容(还可输入'+inttostr(SMS_MaxUnicode)+'个双字节字符)';
end;
case EditState_SMS of
ReadSMS:
begin
RadioButton_send.Enabled:=false;
RadioButton_savesend.Enabled:=false;
RadioButton_save.Enabled:=false;
if temptext1='SIM' then
begin
RadioButton_copy.Enabled:=true;
end else
begin
RadioButton_copy.Enabled:=false;
end;
if ((temptext2='SMS MT') or (temptext2='REC UNREAD') or (temptext2='REC READ')) then
begin
RadioButton_RE.Enabled:=true
end else
RadioButton_RE.Enabled:=false;
RadioButton_Forward.Enabled:=true;
RadioButton_Delete.Enabled:=true;
// RadioButton_savePC.Enabled:=true;
RadioButton_savePC.Checked:=true;
RadioButton_savePC.Checked:=false;
Button_handin.Enabled:=false;
Button_Delete.Enabled:=false;
Button_search.Enabled:=false;
Edit_number.Text:='';
Edit_number.ReadOnly:=true;
Edit_msg.ReadOnly:=true;
GroupBox_action.SetFocus;
Form_ShortMessage.Caption:='查看短消息';
if form_main.ListView_Shortmessage_main.Selected.SubItems[4]<>'' then
Form_ShortMessage.Caption:=Form_ShortMessage.Caption+' 时间:'+form_main.ListView_Shortmessage_main.Selected.SubItems[4];
end;
ReSMS:
begin
RadioButton_send.Enabled:=true;
RadioButton_savesend.Enabled:=true;
RadioButton_save.Enabled:=true;
RadioButton_copy.Enabled:=false;
RadioButton_Re.Enabled:=false;
RadioButton_Forward.Enabled:=false;
RadioButton_Delete.Enabled:=false;
RadioButton_savePC.Enabled:=true;
RadioButton_savePC.Checked:=true;
RadioButton_savePC.Checked:=false;
Button_handin.Enabled:=false;
Button_Delete.Enabled:=false;
Button_search.Enabled:=false;
Edit_number.Text:='';
Edit_number.ReadOnly:=true;
Edit_msg.ReadOnly:=false;
Edit_msg.Clear;
Edit_msg.SetFocus;
Form_ShortMessage.Caption:='回复短消息';
end;
ForwardSMS:
begin
RadioButton_send.Enabled:=true;
RadioButton_savesend.Enabled:=true;
RadioButton_save.Enabled:=true;
RadioButton_copy.Enabled:=false;
RadioButton_Re.Enabled:=false;
RadioButton_Forward.Enabled:=false;
RadioButton_Delete.Enabled:=false;
// RadioButton_savePC.Enabled:=true;
RadioButton_savePC.Checked:=true;
RadioButton_savePC.Checked:=false;
Button_handin.Enabled:=true;
Button_Delete.Enabled:=true;
Button_search.Enabled:=true;
ListView_number.Clear;
Edit_number.Text:='';
Edit_number.ReadOnly:=false;
Edit_msg.ReadOnly:=false;
Edit_number.SetFocus;
Form_ShortMessage.Caption:='转发短消息';
end;
NewSMS:
begin
RadioButton_send.Enabled:=true;
RadioButton_savesend.Enabled:=true;
RadioButton_save.Enabled:=true;
RadioButton_copy.Enabled:=false;
RadioButton_Re.Enabled:=false;
RadioButton_Forward.Enabled:=false;
RadioButton_Delete.Enabled:=false;
RadioButton_savePC.Enabled:=true;
RadioButton_savePC.Checked:=true;
RadioButton_savePC.Checked:=false;
Button_handin.Enabled:=true;
Button_Delete.Enabled:=true;
Button_search.Enabled:=true;
ListView_number.Clear;
if trim(sendnum)<>'' then
begin
tempitem:=ListView_number.Items.Add;
tempitem.Caption:=sendnum;
tempitem.SubItems.Add(sendname);
sendnum:='';
sendname:='';
end;
Edit_number.Text:='';
Edit_number.ReadOnly:=false;
Edit_msg.ReadOnly:=false;
Edit_msg.Clear;
Edit_msg.SetFocus;
Form_ShortMessage.Caption:='新建短消息';
end;
ModifySMS:
begin
RadioButton_send.Enabled:=true;
RadioButton_savesend.Enabled:=true;
RadioButton_save.Enabled:=true;
RadioButton_copy.Enabled:=false;
RadioButton_Re.Enabled:=false;
RadioButton_Forward.Enabled:=false;
RadioButton_Delete.Enabled:=false;
RadioButton_savePC.Enabled:=true;
RadioButton_savePC.Checked:=true;
RadioButton_savePC.Checked:=false;
Button_handin.Enabled:=true;
Button_Delete.Enabled:=true;
Button_search.Enabled:=true;
Edit_number.Text:='';
Edit_number.ReadOnly:=false;
Edit_msg.ReadOnly:=false;
Edit_msg.SetFocus;
Form_ShortMessage.Caption:='编辑短消息';
end;
end;
// ListView_number.captionItems.Add(format('%-17s',[form_main.ListView_Shortmessage_main.Selected.SubItems[2]]));
Timer_sms.Enabled:=true;
end;
procedure TForm_ShortMessage.Edit_numberChange(Sender: TObject);
var i:integer;
temptext:string;
begin
temptext:=(sender as TEdit).Text;
if trim(temptext)='' then exit;
for i:=1 to length(temptext) do
begin
if not(temptext[i] in NumberSet) then
begin
showmessage('输入有不合法字符');
(sender as TEdit).SetFocus;
(sender as TEdit).SelStart:=i-1;
(sender as TEdit).SelLength:=length(temptext)-(i-1);
Button_handin.Enabled:=false;
// (sender as TEdit).SelText:='';
exit;
end;
end;
Button_handin.Enabled:=true;
end;
procedure TForm_ShortMessage.Edit_numberKeyPress(Sender: TObject; var Key: Char);
begin
if not(key in NumberSet) then key:=#0;
end;
procedure TForm_ShortMessage.Edit_numberExit(Sender: TObject);
var i:integer;
temptext:string;
begin
temptext:=(sender as TEdit).Text;
if trim(temptext)='' then exit;
for i:=1 to length(temptext) do
begin
if not(temptext[i] in NumberSet) then
begin
showmessage('输入有不合法字符');
(sender as TEdit).SetFocus;
(sender as TEdit).SelStart:=i-1;
(sender as TEdit).SelLength:=length(temptext)-(i-1);
// (sender as TEdit).SelText:='';
break;
end;
end;
end;
procedure TForm_ShortMessage.Button_handinClick(Sender: TObject);
var tempitem:TListItem;
begin
if trim(Edit_number.Text)<>'' then
begin
if ListView_number.Items.Count=0 then
begin
tempitem:=ListView_number.Items.Add;
tempitem.Caption:=Edit_number.Text;
tempitem.SubItems.Add('');
end;
end;
end;
procedure TForm_ShortMessage.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Timer_sms.Enabled:=false;
OKBtn.Enabled:=false;
end;
procedure TForm_ShortMessage.Button_searchClick(Sender: TObject);
var tempitem:TListItem;
begin
if Form_phbsearch.ShowModal=mrOK then
begin
if Form_phbsearch.ListView_phbsearch.Selected<>nil then
begin
if ListView_number.Items.Count=0 then
begin
tempitem:=ListView_number.Items.Add;
tempitem.Caption:=Form_phbsearch.ListView_phbsearch.Selected.SubItems[1];
tempitem.SubItems.Add(Form_phbsearch.ListView_phbsearch.Selected.SubItems[0]);
end;
end;
end;
end;
procedure TForm_ShortMessage.Button_deleteClick(Sender: TObject);
begin
ListView_number.DeleteSelected;
Edit_number.SetFocus;
end;
procedure TForm_ShortMessage.Timer_smsTimer(Sender: TObject);
begin
if (RadioButton_send.Checked) or(RadioButton_savesend.checked)or(RadioButton_save.Checked)
or(RadioButton_copy.Checked)or(RadioButton_Re.Checked)or(RadioButton_Forward.Checked)
or(RadioButton_Delete.Checked)or(RadioButton_savePC.Checked) then
begin
if (RadioButton_send.Checked) or(RadioButton_savesend.checked) then
begin
if ListView_number.Items.Count>0 then
okBtn.Enabled:=true
else
okBtn.Enabled:=false;
end else
okBtn.Enabled:=true;
end else
okBtn.Enabled:=false;
end;
procedure TForm_ShortMessage.OKBtnClick(Sender: TObject);
begin
modalresult:=mrNone;
if (RadioButton_re.Checked) then
begin
EditState_SMS:=ReSMS;//save to flash
FormActivate(self);
exit;
end;
if (RadioButton_Forward.Checked) then
begin //只有针对sim卡中的短消息才能做save to flash,手机内的短消息不可能做这一步
EditState_SMS:=ForwardSMS;//save to flash
FormActivate(self);
exit;
end;
modalresult:=mrOK;
end;
procedure TForm_ShortMessage.Edit_msgChange(Sender: TObject);
var i:integer;
ts:string;
singlebytecount:integer;
doublebytecount:integer;
isdoublebyte:boolean;
begin
ts:=edit_msg.Text;
singlebytecount:=0;
doublebytecount:=0;
isdoublebyte:=false;
for i:=1 to length(ts) do
begin
if ByteType(ts,i)=mbSingleByte then inc(singlebytecount)
else isdoublebyte:=true;
end;
if isdoublebyte then
begin
doublebytecount:=(length(ts)-singlebytecount)div 2;
if doublebytecount+singlebytecount>SMS_MaxUnicode then
begin
edit_msg.Text:=copy(ts,1,SMS_MaxUnicode);
edit_msg.MaxLength:=SMS_MaxUnicode;
GroupBox_msg.Caption:='内容(还可输入0个双字节字符)';
end else
begin
edit_msg.MaxLength:=SMS_MaxUnicode*2-singlebytecount;
GroupBox_msg.Caption:='内容(还可输入'+inttostr(SMS_MaxUnicode-doublebytecount-singlebytecount)+'个双字节字符)';
end;
end else
begin
GroupBox_msg.Caption:='内容(还可输入'+inttostr(SMS_MaxASC-singlebytecount)+'个单字节字符)';
edit_msg.MaxLength:=SMS_MaxASC;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -