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

📄 main.pas

📁 是一个手机功能的模拟程序
💻 PAS
📖 第 1 页 / 共 5 页
字号:
      if p<>nil then
      begin
        freemem(p);
        p:=nil;
      end;
      configphblist;
      docompletephb;
      exit;
    end;
    PC_PHB_status_getPHBcount: //获得Sim电话本和手机电话本里的电话号码数目后,处理
    begin
      doPHBCount(p);
      form_main.Panel_Phb.Caption:='电话簿: PC中条目数:'+inttostr(Count_PHB_PC)
                                  +',手机存储器中条目数:'+inttostr(Count_PHB_NVM)+'(最多'+inttostr(Max_PHB_NVM)
                                  +'),SIM卡中条目数:'+inttostr(Count_PHB_SIM)+'(最多'+inttostr(Max_PHB_SIM)+')';
      form_main.statusbar1.Panels[0].Text:='正在下载电话簿信息...';
//      form_main.statusbar1.Panels[0].Text:=inttostr(Count_PHB_NVM)+','+inttostr(Count_PHB_SIM)+','+inttostr(Count_PHB_PC)+','+inttostr(CurTable);

      if Count_PHB_NVM+Count_PHB_SIM+Count_PHB_PC>0 then
      begin
        form_progressbar.Label_status.Caption:='';
        showstr:=inttostr(Count_PHB_PC+Count_PHB_NVM+Count_PHB_SIM);
        form_progressbar.Label_status.Caption:='正在下载电话簿('+inttostr(Count_PHB_PC)+'/'+showstr+')';
        form_progressbar.ProgressBar1.Max:=Count_PHB_PC+Count_PHB_SIM+Count_PHB_NVM+1;
        form_progressbar.ProgressBar1.Min:=1;
        form_progressbar.ProgressBar1.Step:=1;
        form_progressbar.ProgressBar1.Position:=Count_PHB_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;
      CurPHB_index:=1;
      while (PhoneBookList.Count>Count_PHB_PC) do//清空所有的非PC_phb记录
      begin
        freemem(Pchar(PhoneBookList[Count_PHB_PC]));
        PhoneBookList.Delete(Count_PHB_PC);
      end;

      if CurPHB_index<=Count_PHB_NVM+Count_PHB_SIM then
      begin
        status_PHB:=PC_PHB_status_getPHBList;
        GetPHBContent(ALL_BOOK_SEL,CurPHB_index,@pc_callback_PHBGetInfo); //获取电话簿列表时,不用指定类型,下载的记录中带有类型信息
        exit;
      end;
    end;
    PC_PHB_status_getPHBList:
    begin
      doPHBList(p);
      form_progressbar.Label_status.Caption:='正在下载电话簿('+inttostr(CurPHB_index+Count_PHB_PC)+'/'+inttostr(Count_PHB_PC+Count_PHB_NVM+Count_PHB_SIM)+')';
      form_progressbar.ProgressBar1.StepIt;
      inc(CurPHB_index);//下一条记录
      if CurPHB_index<=Count_PHB_NVM+Count_PHB_SIM then
      begin
        GetPHBContent(ALL_BOOK_SEL,CurPHB_index,@pc_callback_PHBGetInfo);
        exit;
      end;
      form_main.StatusBar1.Panels[0].Text:='下载电话簿记录已完成';
     //全部完成后,跳出case,执行最后一段在界面上显示收到的内容
    end;
    PC_PHB_status_DelPHB:
    begin
      doDelPHB(p);
      form_progressbar.ProgressBar1.Position:=form_progressbar.ProgressBar1.Max;
      configphblist;//将删除的短消息从shortmessagelist中删除
      CurInsPHB_Index:=-1;
      form_main.StatusBar1.Panels[0].Text:='删除电话簿记录已完成';
    end;
    PC_PHB_status_AddPHB:
    begin
      doputPHBRecord(p);
      if CurInsPHB_Index>=0 then
        PPhoneBook(phonebooklist[CurInsPHB_Index]).serialNo:=strtoint(PPhoneBook(phonebooklist[CurInsPHB_Index]).SN);
      configphblist;
      CurInsPHB_Index:=-1;
      form_main.StatusBar1.Panels[0].Text:='新建电话簿记录已完成';
    end;
    PC_PHB_status_EditPHB:
    begin
      //更新完后再次去刷新phonebooklist中的内容
      doputPHBRecord(p);
      if CurInsPHB_Index>=0 then
      begin
        tempphb:=PPhoneBook(phonebooklist[CurInsPHB_Index]);
        UnicodetoASC(tempphb.data.phkitem.name,objname); //将姓名unicode中文转换为asc
        strcopy(tempPHB.Name,objname);
        strcopy(tempPHB.number,tempPHB.data.phkitem.number);
        strcopy(tempPHB.office,tempPHB.data.phkitem.office);
        strcopy(tempPHB.home,tempPHB.data.phkitem.home);
        UnicodetoASC(tempPHB.data.phkitem.memo,objmemo); //将姓名unicode中文转换为asc
        strcopy(tempPHB.memo,objmemo);
        if tempphb.Location='手机' then //只有手机类型才需要去更新组别
          tempPHB.group:=infotogroup(tempPHB.data.phkitem.info);
      end;
      CurInsPHB_Index:=-1;
      form_main.StatusBar1.Panels[0].Text:='更新电话簿记录已完成';
    end;
  end;
  CurPHB_index:=1;
  status_PHB:=PC_PHB_status_init;
  form_main.Panel_Phb.Caption:='电话簿: PC中条目数:'+inttostr(Count_PHB_PC)
                                +',手机存储器中条目数:'+inttostr(Count_PHB_NVM)+'(最多'+inttostr(Max_PHB_NVM)
                                +'),SIM卡中条目数:'+inttostr(Count_PHB_SIM)+'(最多'+inttostr(Max_PHB_SIM)+')';

  form_progressbar.ProgressBar1.Position:=1;

  form_progressbar.Hide;
  form_progressbar.close;
//根据上次选择显示的状态来显示新的内容
  case Form_main.FLastViewState_phonebook of
  ALL_PHB:Form_main.SpeedButton_phonebookClick(nil);
  V_PHB:  Form_main.ListView_phonebook_subClick(nil);
  S_PHB:  Form_main.ListView_phonebook_subClick(nil);
  P_PHB:  Form_main.ListView_phonebook_subClick(nil);
  end;
end;

procedure TForm_main.AddPHBtoPC(ulrecn:PPC_PHB_Content);
var tempphb:PPhoneBook;
    objname:array[0..PHB_name_len+3-1] of char;
    objmemo:array[0..PHB_memo_len+3-1] of char;
begin
  Query1.Active:=False;
  Query1.SQL.Clear;
  Query1.SQL.Text:='insert into phonebook (Name,PhoneNo,HomeNo,OfficeNo,[Memo]) values (:Name,:PhoneNo,:HomeNo,:OfficeNo,:[Memo])';
  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);
  UnicodetoASC(ulrecn.phkitem.memo,objmemo); //将姓名unicode中文转换为asc
  Query1.Parameters.ParamByName('[Memo]').Value:=strpas(objmemo);
  Query1.ExecSQL;
  Query1.close;
  ADOQuery_phb.Close;
  ADOQuery_phb.SQL.Clear;
  ADOQuery_phb.SQL.Add('select * from phonebook');
  ADOQuery_phb.Open;
  ADOQuery_phb.Last;
  if adoquery_phb.RecordCount<=0 then exit;

  getmem(tempphb,sizeof(TPhoneBook));
  fillchar(tempphb^,sizeof(TPhoneBook),#0);
  move(ulrecn^,tempphb.data,sizeof(TPC_PHB_Content));
  tempphb.Location:='PC';
//SN存放的是sim和flash电话簿类型在手机中的唯一索引号,sim和flash两种类别是混合在一起的,这个值是连续的
//对于PC类型,sn存放的则是顺序号
  strpcopy(tempphb.SN,format('%.3d',[ADOQuery_phb.RecordCount]));
//serialNo现在只有对PC类型有用,存放的是PC类型每条记录在数据库中的自增变量serialNo
//并且当serialNo=-1时表示这条记录失效,configphblist后,就会删除它
  tempphb.serialNo:=ADOQuery_phbSerialNo.asInteger;

  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);
  tempPHB.group:=0; //数据库中没有分组信息

  phonebookList.insert(Count_PHB_PC,tempPHB);
  Count_PHB_PC:=adoquery_phb.RecordCount;
  ADOQuery_phb.Close;
  ListView_PhoneBookSort('');
end;

function TForm_main.AddPHBToList(ulrecn:PPC_PHB_Content;Location:string):integer;
var tempphb:PPhoneBook;
    objname:array[0..PHB_name_len+3-1] of char;
    objmemo:array[0..PHB_memo_len+3-1] of char;
    i,oldcount:integer;
    str1,str2:string;
begin
  result:=-1;
  getmem(tempphb,sizeof(TPhoneBook));
  fillchar(tempphb^,sizeof(TPhoneBook),#0);
  move(ulrecn^,tempphb.data,sizeof(TPC_PHB_Content));

  strpcopy(tempphb.Location,Location);
  strpcopy(tempphb.SN,format('%.3d',[ulrecn.id]));
  UnicodetoASC(ulrecn.phkitem.name,objname); //将姓名unicode中文转换为asc
  strcopy(tempPHB.Name,objname);
  strcopy(tempPHB.number,ulrecn.phkitem.number);
  strcopy(tempPHB.office,ulrecn.phkitem.office);
  strcopy(tempPHB.home,ulrecn.phkitem.home);
  UnicodetoASC(ulrecn.phkitem.memo,objmemo); //将姓名unicode中文转换为asc
  strcopy(tempPHB.memo,objmemo);

  tempphb.serialNo:=-1;
  if Location='手机' then
  begin
    tempPHB.group:=infotogroup(ulrecn.phkitem.info);

    oldcount:=phonebooklist.count;
    for i:=Count_PHB_PC to Count_PHB_PC+Count_PHB_NVM-1 do
    begin
      str1:=PPhonebook(phonebooklist.Items[i]).SN;
      str2:=tempPHB.SN;
      if CompareText(str2,str1)>0 then continue;
      phonebooklist.Insert(i,tempPHB);
      result:=i;
      break;
    end;
    if phonebooklist.count=oldcount then//如果id是最大的,那么就把这条记录放在最后
    begin
      PhoneBookList.Insert(Count_PHB_PC+Count_PHB_NVM,tempPHB);
      result:=Count_PHB_PC+Count_PHB_NVM;
    end;
    inc(Count_PHB_NVM);
  end;
  if Location='SIM' then
  begin
    tempPHB.group:=0;
    oldcount:=phonebooklist.count;
    for i:=Count_PHB_PC+Count_PHB_NVM to Count_PHB_PC+Count_PHB_NVM+Count_PHB_SIM-1 do
    begin
      str1:=PPhonebook(phonebooklist.Items[i]).SN;
      str2:=tempPHB.SN;
      if CompareText(str2,str1)>0 then continue;
      phonebooklist.Insert(i,tempPHB);
      result:=i;
      break;
    end;
    if phonebooklist.count=oldcount then//如果id是最大的,那么就把这条记录放在最后
    begin
      PhoneBookList.add(tempPHB);
      result:=Count_PHB_PC+Count_PHB_NVM+Count_PHB_SIM;
    end;
    inc(Count_PHB_SIM);
  end;
end;

procedure TForm_main.AddPHB;
var tempPHBRec:TPC_PHB_Content;
    tempindex:integer;
    temptype:T_MFW_PHB_SELECT;
    objname:array[0..PHB_name_len+3-1] of char;
    objmemo:array[0..PHB_memo_len+3-1] of char;
    i:integer;
begin
  if Form_Phonebook.ShowModal=mrOK then
  begin
    tempindex:=0;//index=0,表示新记录
    fillchar(tempPHBRec,sizeof(tempPHBRec),#0);
    fillchar(objname,sizeof(objname),#0);
    strpcopy(objname,Form_Phonebook.Edit_name.Text);
    ASCtoUnicode(objname,tempPHBRec.phkitem.name); //将姓名中文asc转换为unicode
    strpcopy(tempPHBRec.phkitem.number,trim(Form_Phonebook.Edit_phNo.Text));
    strpcopy(tempPHBRec.phkitem.office,trim(Form_Phonebook.Edit_ofNo.Text));
    strpcopy(tempPHBRec.phkitem.home,trim(Form_Phonebook.Edit_hoNo.Text));
    fillchar(objmemo,sizeof(objmemo),#0);
    strpcopy(objmemo,Form_Phonebook.Edit_memo.Text);
    ASCtoUnicode(objmemo,tempPHBRec.phkitem.memo); //将memo中文asc转换为unicode

    if Form_Phonebook.RadioButton_PHB_PC.Checked then
    begin
      tempPHBRec.phkitem.info:=char($40);//无分组信息,低4位为0
      AddPHBtoPC(@tempPHBRec);
    end else
    begin
      if Form_Phonebook.RadioButton_PHB_NVM.Checked then
      begin
        if Count_PHB_NVM>=Max_PHB_NVM then begin showmessage('手机电话簿已满,无法增加新记录!');exit; end;
        temptype:=NVM_BOOK_SEL; //手机电话簿
        tempPHBRec.phonebook:=ord(temptype);
        tempPHBRec.phkitem.info:=grouptoinfo(Form_Phonebook.ComboBox_group.ItemIndex);//分组信息,初始为没有分组,低4位为F
        for i:=Count_PHB_PC to Count_PHB_PC+Count_PHB_NVM-1 do
        begin
          if (i-Count_PHB_PC+1>=PPhonebook(phonebooklist[i]).data.id) then continue;
          break;
        end;
        if Count_PHB_NVM=0 then i:=Count_PHB_PC;
        tempPHBRec.id:=i-Count_PHB_PC+1;//找到空的位置存放,序号从1开始
        CurInsPHB_Index:=AddPHBtoList(@tempPHBRec,'手机');
      end;
      if Form_Phonebook.RadioButton_PHB_SIM.Checked then
      begin
        if Count_PHB_SIM>=Max_PHB_SIM then begin showmessage('SIM卡电话簿已满,无法增加新记录!');exit; end;
        temptype:=SIM_BOOK_SEL; //SIM卡电话簿
        tempPHBRec.phonebook:=ord(temptype);
        tempPHBRec.phkitem.info:=char($40);//无分组信息,低4位为0
        for i:=Count_PHB_PC+Count_PHB_NVM to Count_PHB_PC+Count_PHB_NVM+Count_PHB_SIM-1 do
        begin
          if (i-Count_PHB_PC-Count_PHB_NVM+1>=PPhonebook(phonebooklist[i]).data.id) then continue;
          break;
        end;
        if Count_PHB_SIM=0 then i:=Count_PHB_PC+Count_PHB_NVM;
        tempPHBRec.id:=i-Count_PHB_PC-Count_PHB_NVM+1;//找到空的位置存放
        CurInsPHB_Index:=AddPHBtoList(@tempPHBRec,'SIM');
      end;
      status_PHB:=PC_PHB_status_AddPHB;
      putPhbRecord(temptype,tempindex,@tempPHBRec.phkitem,@pc_callback_PHBGetInfo);
      form_progressbar.Label_status.Caption:='正在上载电话簿记录';
      form_progressbar.ProgressBar1.Max:=1;
      form_progressbar.ProgressBar1.Min:=1;
      form_progressbar.ProgressBar1.Step:=1;
      form_progressbar.ProgressBar1.Position:=1;
      form_progressbar.Showmodal;
    end;
  end;
end;

function TForm_main.DeletePHBinPC(id:integer):boolean;
begin
  result:=false;
  if id>0 then
  begin
    query1.SQL.Clear;
    query1.SQL.Add('delete from phonebook where ');
    query1.SQL.Add(' SerialNo='+inttostr(id));
    try
      query1.ExecSQL;
      result:=true;

⌨️ 快捷键说明

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