main.pas
来自「是一个手机功能的模拟程序」· PAS 代码 · 共 1,568 行 · 第 1/5 页
PAS
1,568 行
except
result:=false;
end;
end;
end;
procedure TForm_main.UpdatePHBtoPC(ulrecn:PPC_PHB_Content;sn:integer);
var objname:array[0..PHB_name_len+3-1] of char;
tempPHB:PPhoneBook;
i:integer;
begin
Query1.Active:=False;
Query1.SQL.Clear;
Query1.SQL.Text:='UPDATE phonebook SET Name=:Name,PhoneNo=:PhoneNo,HomeNo=:HomeNo,OfficeNo=:OfficeNo,[Memo]=:[Memo] WHERE SerialNo=:SerialNo';
UnicodetoASC(ulrecn.phkitem.name,objname); //将姓名unicode中文转换为asc
Query1.Parameters.ParamByName('Name').Value:=strpas(objname);
Query1.Parameters.ParamByName('PhoneNo').Value:=strpas(ulrecn.phkitem.number);
Query1.Parameters.ParamByName('HomeNo').Value:=strpas(ulrecn.phkitem.home);
Query1.Parameters.ParamByName('OfficeNo').Value:=strpas(ulrecn.phkitem.office);
Query1.Parameters.ParamByName('[Memo]').Value:=strpas(ulrecn.phkitem.memo);
Query1.Parameters.ParamByName('SerialNo').Value:=sn;
Query1.ExecSQL;
Query1.close;
ADOQuery_phb.Close;
ADOQuery_phb.SQL.Clear;
ADOQuery_phb.SQL.Add('select * from phonebook where SerialNo='+inttostr(sn));
ADOQuery_phb.Open;
tempphb:=nil;
for i:=0 to Count_PHB_PC-1 do
begin
if PPhoneBook(phonebookList.Items[i]).serialNo=sn then
begin
tempphb:=PhoneBookList.Items[i];
break;
end;
end;
if tempphb=nil then exit;
move(ulrecn^,tempphb.data,sizeof(TPC_PHB_Content));
strpcopy(tempPHB.Name,ADOQuery_phbName.AsString);
strpcopy(tempPHB.number,ADOQuery_phbPhoneNo.AsString);
strpcopy(tempPHB.office,ADOQuery_phbOfficeNo.AsString);
strpcopy(tempPHB.home,ADOQuery_phbHomeNo.AsString);
strpcopy(tempPHB.memo,ADOQuery_phbMemo.AsString);
//这里已经从Form_ShortMessage中获取了大部分信息,但是还缺短信息类型和时间
ADOQuery_phb.Close;
ListView_PhoneBookSort('');
end;
function TForm_main.UpdatePHBToList(ulrecn:PPC_PHB_Content;id:integer):integer;
var tempphb:PPhoneBook;
begin
result:=-1;
tempphb:=PPhoneBook(phonebookList.Items[id]);
if tempphb=nil then exit;
move(ulrecn^,tempphb.data,sizeof(TPC_PHB_Content));
result:=id;
end;
//*****************shortmessage*********************//
procedure configsmslist;
var listcount:integer;
begin
listcount:=ShortMessageList.Count;
// ShortMessageList.Sort();
while listcount>0 do
begin
if PShortMessage(ShortMessageList.Items[listcount-1]).serialNo=-1 then
begin
if PShortMessage(ShortMessageList.Items[listcount-1]).location='PC' then
dec(Count_SMS_PC);
if PShortMessage(ShortMessageList.Items[listcount-1]).location='手机' then
begin
if PShortMessage(ShortMessageList.Items[listcount-1]).sort='SMS MT' then
dec(Count_SMS_Flash_MT)
else
dec(Count_SMS_Flash_MO);
Count_SMS_Flash:= Count_SMS_Flash_MO+Count_SMS_Flash_MT;
end;
if PShortMessage(ShortMessageList.Items[listcount-1]).location='SIM' then
begin
if (PShortMessage(ShortMessageList.Items[listcount-1]).sort='STO UNSENT')
or (PShortMessage(ShortMessageList.Items[listcount-1]).sort='STO SENT') then
dec(Count_SMS_SIM_MO);
if (PShortMessage(ShortMessageList.Items[listcount-1]).sort='REC UNREAD')
or (PShortMessage(ShortMessageList.Items[listcount-1]).sort='REC READ') then
dec(Count_SMS_SIM_MT);
Count_SMS_SIM:=Count_SMS_SIM_MO+Count_SMS_SIM_MT;
end;
freemem(ShortMessageList.Items[listcount-1]);
ShortMessageList.Delete(listcount-1);
end;
dec(listcount);
end;
end;
procedure docompletesms;
begin
CurSMS_index:=1;
status_SMS:=PC_SMS_status_init;
form_main.Panel_sms.Caption:='短消息: PC中条目数:'+inttostr(Count_SMS_PC)
+',手机存储器中条目数:'+inttostr(Count_SMS_Flash)+'(最多'+inttostr(MaxCount_SMS_FLash)
+'),SIM卡中条目数:'+inttostr(Count_SMS_SIM)+'(最多'+inttostr(MaxCount_SMS_SIM)+')';
form_progressbar.ProgressBar1.Position:=1;
sleep(1000);
form_progressbar.Hide;
form_progressbar.close;
//根据上次选择显示的状态来显示新的内容
case Form_main.FLastViewState_ShortMessage of
ALL_SMS:Form_main.SpeedButton_ShortMessageClick(nil);
V_SMS: Form_main.ListView_ShortMessage_subClick(nil);
S_SMS: Form_main.ListView_ShortMessage_subClick(nil);
P_SMS: Form_main.ListView_ShortMessage_subClick(nil);
end;
end;
procedure pc_callback_SMSGetInfo(p:pointer);
var tempsmsitem:TPC_SMS_Content;
rp:byte;
begin
if PPC_Interface_Info(p).status<>ord(PC_Error_NoError) then
begin
case pPC_Interface_Info(p).status of
ord(PC_Error_SerialNoResponse):
begin
form_main.statusbar1.Panels[0].Text:='通讯超时,可能串口连接有故障';//说明target响应timeout,for example:serial is invalid
Serial_Close;
Comhandle:=2;
form_main.StatusBar1.Panels[1].Text:='未连接';
end;
ord(PC_Error_MMINotAllow):form_main.statusbar1.Panels[0].Text:='手机未设在同步状态菜单内';//手机不允许pc同步, 要先进入菜单工具箱->pc同步
ord(PC_Error_MMINeedPause):form_main.statusbar1.Panels[0].Text:='有电话进来,同步暂停';
ord(App_Error_DefaultError):form_main.statusbar1.Panels[0].Text:='操作有错误!!!';
ord(App_Error_ReadError):form_main.statusbar1.Panels[0].Text:='读取短消息过程中有错误!';
ord(App_Error_WriteError):form_main.statusbar1.Panels[0].Text:='保存短消息过程中有错误,SIM短消息已存满!';
ord(App_Error_DeleteError):form_main.statusbar1.Panels[0].Text:='删除短消息失败!';
ord(App_Error_CopyError):form_main.statusbar1.Panels[0].Text:='复制短消息到手机过程有错误,手机短消息已存满';
ord(App_Error_InfoError):form_main.statusbar1.Panels[0].Text:='获取短消息信息有错误';
ord(App_Error_SendError):form_main.statusbar1.Panels[0].Text:='发送短消息失败';
ord(App_Error_StoreError):form_main.statusbar1.Panels[0].Text:='存储短消息失败';
end;
if PPC_Interface_Info(p).pdata_cmd<>nil then
freemem(PPC_Interface_Info(p).pdata_cmd);
if PPC_Interface_Info(p).pdata_dlbuff<>nil then
freemem(PPC_Interface_Info(p).pdata_dlbuff);
if PPC_Interface_Info(p).pdata_ulbuff<>nil then
freemem(PPC_Interface_Info(p).pdata_ulbuff);
if p<>nil then
begin
freemem(p);
p:=nil;
end;
configsmslist;
docompletesms;
exit;
end;
case status_SMS of
PC_SMS_status_init://下载取消时
begin
if PPC_Interface_Info(p).pdata_cmd<>nil then
freemem(PPC_Interface_Info(p).pdata_cmd);
if PPC_Interface_Info(p).pdata_dlbuff<>nil then
freemem(PPC_Interface_Info(p).pdata_dlbuff);
if PPC_Interface_Info(p).pdata_ulbuff<>nil then
freemem(PPC_Interface_Info(p).pdata_ulbuff);
if p<>nil then
begin
freemem(p);
p:=nil;
end;
configsmslist;
docompletesms;
exit;
end;
PC_SMS_status_getSMScount: //获得Sim电话本和手机电话本里的电话号码数目后,处理
begin
doSMSCount(p);
form_main.Panel_sms.Caption:='短消息: PC中条目数:'+inttostr(Count_SMS_PC)
+',手机存储器中条目数:'+inttostr(Count_SMS_Flash)+'(最多'+inttostr(MaxCount_SMS_FLash)
+'),SIM卡中条目数:'+inttostr(Count_SMS_SIM)+'(最多'+inttostr(MaxCount_SMS_SIM)+')';
form_main.statusbar1.Panels[0].Text:='正在下载短消息信息...';
{
form_main.Panel_Phb.Caption:='PC='+inttostr(Count_SMS_PC)+
',FlashMO='+inttostr(Count_SMS_Flash_MO)+',FlashMT='+inttostr(Count_SMS_Flash_MT)+
',SIMMO='+inttostr(Count_SMS_SIM_MO)+',SIMMT='+inttostr(Count_SMS_SIM_MT)+',MaxMem='+
inttostr(MaxCount_SMS_SIM);
}
if Count_SMS_Flash+Count_SMS_SIM>0 then
begin
form_progressbar.Label_status.Caption:='';
form_progressbar.Label_status.Caption:='正在下载短消息('+inttostr(Count_SMS_PC)+'/'+inttostr(Count_SMS_PC+Count_SMS_Flash+Count_SMS_SIM)+')';
form_progressbar.ProgressBar1.Max:=Count_SMS_Flash+Count_SMS_SIM+Count_SMS_PC+1;
form_progressbar.ProgressBar1.Min:=1;
form_progressbar.ProgressBar1.Step:=1;
form_progressbar.ProgressBar1.Position:=Count_SMS_PC+1;
end else
begin
form_progressbar.Label_status.Caption:='无短消息';
form_progressbar.ProgressBar1.Max:=2;
form_progressbar.ProgressBar1.Min:=1;
form_progressbar.ProgressBar1.Position:=2;
end;
while (ShortMessageList.Count>Count_SMS_PC) do//清空所有的非PC_phb记录
begin
freemem(Pchar(ShortMessageList[Count_SMS_PC]));
ShortMessageList.Delete(Count_SMS_PC);
end;
CurSMS_index:=1;
if Count_SMS_Flash>0 then
begin
status_SMS:=PC_SMS_status_getFLashSMSList;
if CurSMS_index<=Count_SMS_Flash_MO then
GetSMSContent(PCSYN_SMS_FLASH_MO,CurSMS_index,@pc_callback_SMSGetInfo) //获取电话簿列表时,不用指定类型,下载的记录中带有类型信息
else
if CurSMS_index-Count_SMS_Flash_MO<=Count_SMS_Flash_MT then
GetSMSContent(PCSYN_SMS_FLASH_MT,CurSMS_index-Count_SMS_Flash_MO,@pc_callback_SMSGetInfo); //获取电话簿列表时,不用指定类型,下载的记录中带有类型信息
exit;
end else
begin
if Count_SMS_SIM>0 then
begin
status_SMS:=PC_SMS_status_getSIMSMSList;
GetSMSContent(PCSYN_SMS_ALL,CurSMS_index,@pc_callback_SMSGetInfo); //获取电话簿列表时,不用指定类型,下载的记录中带有类型信息
exit;
end;
end;
end;
PC_SMS_status_getFLashSMSList:
begin
doSMSFlashList(p);
form_progressbar.Label_status.Caption:='正在下载短消息('+inttostr(CurSMS_index+Count_SMS_PC)+'/'+inttostr(Count_SMS_PC+Count_SMS_Flash+Count_SMS_SIM)+')';
form_progressbar.ProgressBar1.StepIt;
inc(CurSMS_index);
//为何要分两种类型PCSYN_SMS_FLASH_MO和PCSYN_SMS_FLASH_MT来取短信?
//因为target端上每次只能获得一种类型数据的列表,所以只能将它们分开取
//target端取短信函数是SortFlashSms(T_MFW_SMS_STAT stat,T_MMI_FLASH_SMS_INDEX * msg_list) ,它是按时间递减排序的
if CurSMS_index<=Count_SMS_Flash then
begin
if CurSMS_index<=Count_SMS_Flash_MO then
GetSMSContent(PCSYN_SMS_FLASH_MO,CurSMS_index,@pc_callback_SMSGetInfo) //获取电话簿列表时,不用指定类型,下载的记录中带有类型信息
else
if CurSMS_index-Count_SMS_Flash_MO<=Count_SMS_Flash_MT then
GetSMSContent(PCSYN_SMS_FLASH_MT,CurSMS_index-Count_SMS_Flash_MO,@pc_callback_SMSGetInfo); //获取电话簿列表时,不用指定类型,下载的记录中带有类型信息
exit;
end else
begin
if Count_SMS_SIM>0 then
begin
CurSMS_index:=1;
status_SMS:=PC_SMS_status_getSIMSMSList;
GetSMSContent(PCSYN_SMS_ALL,CurSMS_index,@pc_callback_SMSGetInfo); //获取电话簿列表时,不用指定类型,下载的记录中带有类型信息
exit;
end;
form_main.statusbar1.Panels[0].Text:='下载短消息记录已完成';
end;
end;
PC_SMS_status_getSIMSMSList:
begin
doSMSSIMList(p);
form_progressbar.Label_status.Caption:='正在下载短消息('+inttostr(CurSMS_index+Count_SMS_PC+Count_SMS_Flash)+'/'+inttostr(Count_SMS_PC+Count_SMS_Flash+Count_SMS_SIM)+')';
form_progressbar.ProgressBar1.StepIt;
inc(CurSMS_index);
if CurSMS_index<=Count_SMS_SIM then
begin
GetSMSContent(PCSYN_SMS_ALL,CurSMS_index,@pc_callback_SMSGetInfo); //获取电话簿列表时,不用指定类型,下载的记录中带有类型信息
exit;
end;
form_main.statusbar1.Panels[0].Text:='下载短消息记录已完成';
//全部完成后,跳出case,执行最后一段在界面上显示收到的内容
end;
PC_SMS_status_DelSMS:
begin
doDelSMS(p);
form_progressbar.Label_status.Caption:='正在删除短消息(还剩'+inttostr(DelSMSList.Count-1)+'条)';
form_progressbar.ProgressBar1.StepIt;
if DelSMSList.Items[0]<>nil then freemem(DelSMSList.Items[0]);
DelSMSList.Delete(0);
if DelSMSList.Count>0 then
begin
delSMS(PDelRec(DelSMSList.Items[0]).ctype,PDelRec(DelSMSList.Items[0]).index,@pc_callback_SMSGetInfo);
exit;
end;
configsmslist;//将删除的短消息从shortmessagelist中删除
form_main.statusbar1.Panels[0].Text:='删除短消息记录已完成';
end;
PC_SMS_status_SendSMS:
begin
//更新完后再次去刷新内容
form_progressbar.Label_status.Caption:='发送短消息成功';
form_progressbar.ProgressBar1.StepIt;
doputSMSRecord(p);
form_main.statusbar1.Panels[0].Text:='发送短消息已完成';
end;
PC_SMS_status_SaveSendSMS:
begin
//更新完后再次去刷新内容
doputSMSRecord(p);
fillchar(tempsmsitem,sizeof(TPC_SMS_Content),#0);
//由于是先发送后存储,所以要把 shortmessagelist里存的那条临时记录再次调出来,做存储的动作
move(PShortMessage(shortmessagelist[CurInsSMS_Index]).data,tempsmsitem,sizeof(TPC_SMS_Content));
rp := 0; //* reply path = 0
status_SMS:=PC_SMS_status_SaveSMS;//save
putSMSRecord(PC_SMS_status_SaveSendSMS,rp,@tempsmsitem,@pc_callback_SMSGetInfo);
exit;
end;
PC_SMS_status_SaveSMS:
begin
//更新完后再次去刷新内容
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?