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

📄 global.pas

📁 是一个手机功能的模拟程序
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    showmessage('无法打开此文件!');
    exit;
  end;

  getmem(tempinfo,sizeof(TPC_Interface_Info));
  getmem(tempcmd_file,sizeof(TPC_App_Cmd_file));
  getmem(tempbuffer_rx,SIZE_BUFFER);

 	fillchar(tempinfo^,sizeof(TPC_Interface_Info),#0);
 	fillchar(tempcmd_file^,sizeof(TPC_App_Cmd_file),#0);
 	fillchar(tempbuffer_rx^,SIZE_BUFFER,#0);

	tempcmd_file.cid1:= PC_AppCID1_File;
	tempcmd_file.cid2:= PC_AppCID2_Write;
  strpcopy(tempcmd_file.filename,Destpath+extractFileName(sourfile));


  readbufsize:=FileRead(filehandle,tempbuffer_rx^,SIZE_BUFFER);
  FileClose(Filehandle);
	tempinfo.flag := PC_IF_FLAGS_DATAUL;
	tempinfo.pdata_cmd:=Pchar(tempcmd_file);
  filelen:=(strlen(tempcmd_file.filename)+2+3)and(not	$03);//字节对齐
	tempinfo.size_cmd:=(strlen(tempcmd_file.filename)+2+3)and(not	$03);//字节对齐

	tempinfo.pdata_ulbuff := tempbuffer_rx;
	tempinfo.size_ulbuff := readbufsize;
	tempinfo.callback := cbfunc;

	pc_interface(tempinfo);
end;

function douploadfile(p:pointer):DWord;
var tempPC_Interface_Info:pPC_Interface_Info;
begin
  tempPC_Interface_Info:=pPC_Interface_Info(p);
  if tempPC_Interface_Info.pdata_cmd<>nil then
    freemem(tempPC_Interface_Info.pdata_cmd);
  if tempPC_Interface_Info.pdata_ulbuff<>nil then
    freemem(tempPC_Interface_Info.pdata_ulbuff);
  if tempPC_Interface_Info<>nil then
    freemem(tempPC_Interface_Info);
end;

procedure Delfile(cbfunc:Pointer;filename:string);
var  tempinfo:pPC_Interface_Info;
     tempcmd_file:pPC_App_Cmd_file;
//     tempbuffer_rx:PChar;
begin
  getmem(tempinfo,sizeof(TPC_Interface_Info));
  getmem(tempcmd_file,sizeof(TPC_App_Cmd_file));

 	fillchar(tempinfo^,sizeof(TPC_Interface_Info),#0);
 	fillchar(tempcmd_file^,sizeof(TPC_App_Cmd_file),#0);

	tempcmd_file.cid1:= PC_AppCID1_File;
	tempcmd_file.cid2:= PC_AppCID2_Delete;
  strpcopy(tempcmd_file.filename,filename);

	tempinfo.flag := PC_IF_FLAGS_DATADL;
	tempinfo.pdata_cmd:=Pchar(tempcmd_file);
	tempinfo.size_cmd:=(strlen(tempcmd_file.filename)+2+3)and(not	$03);//字节对齐

	tempinfo.callback := cbfunc;
	pc_interface(tempinfo);
end;

function doDelFILE(p:pointer):DWord;
var tempPC_Interface_Info:pPC_Interface_Info;
begin
  tempPC_Interface_Info:=pPC_Interface_Info(p);
  result:=tempPC_Interface_Info.status;
  if tempPC_Interface_Info.pdata_cmd<>nil then
    freemem(tempPC_Interface_Info.pdata_cmd);
  if tempPC_Interface_Info<>nil then
    freemem(tempPC_Interface_Info);
end;

//**************Phonebook***************//
function  ASCtoUnicode(Sour:array of char;var Dest:array of char):Word;//将中文转换成unicode字符
var objlen:Dword;
    c:char;
    i,loop:integer;
    isdoublebyte:boolean;
begin
  isdoublebyte:=false;
  for i:=0 to high(sour)-low(sour) do
  begin
    //判断是否是双字节的字符,如果是则把所有的字节全部转换成双字节的unicode
    if StrByteType(sour,i)<>mbSingleByte	 then
    begin
      isdoublebyte:=true;
      break;
    end;
  end;
  if isdoublebyte then
  begin
    objlen:=MultiByteToWideChar(CP_ACP,0,Sour,-1,nil,0);
    result:=(MultiByteToWideChar(CP_ACP,0,Sour,-1,PWideChar(@Dest[LOW(Dest)+1]),objlen)-1)*2+1; //转换成unicode后的字节,最后加1是为了在dest[0]置$80
    Dest[LOW(Dest)]:=char($80);
    loop:=LOW(Dest)+1;//跳过第一个字符
    //如果放字符的长度是双数,则所有的字节都要两两互换
    //如果放字符的长度是单数,则最后一个字节不要互换
    while loop<=((HIGH(Dest)-LOW(Dest)) div 2 *2) do//  姓名段分配长度为16,但是去掉开头的$80,所以应该只剩下15个字节,我们只交换从1到14位置的字节
    begin  //注意,这里在做高低字节互换,手机传过来的unicode字符(word),需要进行高低字节的互换
      c:=Dest[loop];
      Dest[loop]:= Dest[loop+1];
      inc(loop);
      Dest[loop]:=c;
      inc(loop);
    end;
  end else
  begin
    ASC2toGSM(Sour,Dest,strlen(sour));
    result:=strlen(Dest);
  end;
end;

procedure UnicodetoASC(Sour:array of char;var Dest:array of char);
var objlen:Dword;
    c:char;
    loop:integer;
begin
  if Sour[LOW(Sour)]=char($80) then//第一个字节如果是$80,那么后面就是unicode的格式,两个字节表示一个字符
  begin
    loop:=LOW(Sour)+1;//跳过第一个字符
    //如果放字符的长度是双数,则所有的字节都要两两互换
    //如果放字符的长度是单数,则最后一个字节不要互换
    while loop<=((HIGH(Sour)-LOW(Sour)) div 2 *2) do//  姓名段分配长度为16,但是去掉开头的$80,所以应该只剩下15个字节,我们只交换从1到14位置的字节
    begin  //注意,这里在做高低字节互换,手机传过来的unicode字符(word),需要进行高低字节的互换
      c:=Sour[loop];
      Sour[loop]:= Sour[loop+1];
      inc(loop);
      Sour[loop]:=c;
      inc(loop);
    end;
    objlen:=WideCharToMultiByte(CP_ACP,0, PWideChar(@Sour[LOW(Sour)+1]),-1,Nil,0,nil,nil);
    WideCharToMultiByte(CP_ACP, 0, PWideChar(@Sour[LOW(Sour)+1]), -1, Dest, objlen, nil, nil);
  end else
  begin
    strcopy(Dest,Sour);
  end;
end;

procedure UnicodetoASC2(Sour:array of char;var Dest:array of char;strsize:integer);
var objlen:Dword;
    c:char;
    loop:integer;
    i:integer;
begin
  loop:=LOW(Sour);
  //如果字符的长度是双数,则所有的字节都要两两互换
  //如果放字符的长度是单数,则最后一个字节不要互换
  for i:=0 to (strsize div 2-1) do
  begin  //注意,这里在做高低字节互换,手机传过来的unicode字符(word),需要进行高低字节的互换
    c:=Sour[loop];
    Sour[loop]:= Sour[loop+1];
    inc(loop);
    Sour[loop]:=c;
    inc(loop);
  end;
  sour[strsize]:=#0;
  objlen:=WideCharToMultiByte(CP_ACP,0, PWideChar(@Sour[LOW(Sour)]),-1,Nil,0,nil,nil);
  WideCharToMultiByte(CP_ACP, 0, PWideChar(@Sour[LOW(Sour)]), -1, Dest, objlen, nil, nil);
end;

procedure GSMtoASC2(Sour:array of char;var Dest:array of char;strsize:integer);
var i:integer;
    ch:byte;
begin
  for i:=0 to strsize-1 do
  begin
  //    Dest[i]:=char(g_ascii_gsm_table[byte(g_gsm_ascii_table[byte(Sour[i]) and $7F])]);
    ch:=g_gsm_ascii_table[byte(Sour[i]) and $7F];
    if ch>127 then
      Dest[i]:=char(g_ascii_gsm_table[ch])
    else
      Dest[i]:=char(ch);
  end;
end;

procedure ASC2toGSM(Sour:array of char;var Dest:array of char;strsize:integer);
var i:integer;
    ch:byte;
begin
  for i:=0 to strsize-1 do
  begin
  //    Dest[i]:=char(g_ascii_gsm_table[byte(g_gsm_ascii_table[byte(Sour[i]) and $7F])]);

    ch:=g_gsm_ascii_table[byte(Sour[i])];
    if (ch=$20) then
    begin
       ch:=g_ascii_gsm_table[byte(Sour[i])];
       Dest[i]:=char(ch);
    end else
      if (ch>127) then
        Dest[i]:=char(g_ascii_gsm_table[ch and $7F])
      else
        Dest[i]:=char(ch);
  end;
end;

function infotogroup(info:char):byte;
var tempchar:byte;
begin
  tempchar:=ord(info) and $0F;
  if (tempchar)=$0F then
    result:=0
  else
    result:=tempchar+1;
end;

function grouptoinfo(gp:byte):char;
begin
  if gp=0 then result:=chr($5F)
  else result:=chr($50 or ((gp-1) and $0F));
end;

procedure UnCompressNum(CompNum:PChar;var Num:array of char);
var j,ExitFlag:integer;
    GetByte:byte;
begin
  j:=0;
  ExitFlag:=0;
  while ExitFlag=0 do
  begin
//高4位
    GetByte:=(byte(CompNum^) shr 4) and $0F;
    if (GetByte<>$00) then
    begin
      if GetByte=2 then
        Num[j]:=#35 //表示'#'号
      else
        if GetByte=3 then
          Num[j]:=#42 //表示'*'号
        else
          if GetByte=4 then
            Num[j]:=#112 //表示'p'号
          else
            Num[j]:=char(GetByte+48-6);//如果是数字需要减去6
      inc(j);
    end else
    begin
      Num[j]:=#0;
      ExitFlag:=1;
    end;
//低4位
    if ExitFlag<>1 then
    begin
      GetByte:=byte(CompNum^) and $0F;
      if (GetByte<>$00) then
      begin
        if GetByte=2 then
          Num[j]:=#35      //表示'#'号
        else
          if GetByte=3 then
            Num[j]:=#42    //表示'*'号
          else
             if GetByte=4 then
               Num[j]:=#112  //表示'p'号
             else
               Num[j]:=char(GetByte+48-6);//如果是数字需要减去6
         inc(j);
      end else
      begin
        Num[j]:=#0;
        ExitFlag:=1;
      end;
      inc(CompNum);
    end;
  end;
end;

//发送获取PhoneBook数量命令
procedure getPHBCount(cbfunc:Pointer);//向手机发出获得各种电话簿的数量请求
var  tempinfo:pPC_Interface_Info;
     tempcmd_phb:pPC_App_Cmd_PHB;
     tempbuffer_rx:PChar;
begin
  getmem(tempinfo,sizeof(TPC_Interface_Info));
  getmem(tempcmd_phb,sizeof(TPC_App_Cmd_PHB));
  getmem(tempbuffer_rx,SIZE_BUFFER);

 	fillchar(tempinfo^,sizeof(TPC_Interface_Info),#0);
 	fillchar(tempcmd_phb^,sizeof(TPC_App_Cmd_PHB),#0);
 	fillchar(tempbuffer_rx^,SIZE_BUFFER,#0);

	tempcmd_phb.cid1:= PC_AppCID1_PHB;
	tempcmd_phb.cid2:= PC_AppCID2_Info;

	tempinfo.flag := PC_IF_FLAGS_DATADL;
	tempinfo.pdata_cmd:=Pchar(tempcmd_phb);
	tempinfo.size_cmd:= sizeof(TPC_App_Cmd_PHB);

	tempinfo.pdata_dlbuff := tempbuffer_rx;
	tempinfo.size_dlbuff := SIZE_BUFFER;
	tempinfo.callback := cbfunc;

	pc_interface(tempinfo);
end;

//回调函数中处理PhoneBook数量的命令
function doPHBCount(p:pointer):DWord;  //处理回调返回电话簿记录个数的情况
var tempPC_Interface_Info:pPC_Interface_Info;
//    buff:array[0..SIZE_BUFFER-1] of char;
    PC_PHB_count:TPC_PHB_Count;
begin
  tempPC_Interface_Info:=pPC_Interface_Info(p);
  result:=tempPC_Interface_Info.status;
  if tempPC_Interface_Info.size_dlbuff>0 then
  begin
//    fillchar(buff,sizeof(buff),#0);
//    move(tempPC_Interface_Info.pdata_dlbuff^,buff[0],tempPC_Interface_Info.size_dlbuff);
    move(tempPC_Interface_Info.pdata_dlbuff^,PC_PHB_count,sizeof(TPC_PHB_Count));
    Count_PHB_NVM:=PC_PHB_count.NVMTotal;
    Count_PHB_SIM:=PC_PHB_count.SIMTotal;
  	Max_PHB_NVM:=PC_PHB_count.MaxNVM;
    Max_PHB_SIM:=PC_PHB_count.MaxSIM;
  end else
  begin
    Count_PHB_SIM:=0;
    Count_PHB_NVM:=0;
  	Max_PHB_NVM:=0;
    Max_PHB_SIM:=0;
  end;

  if tempPC_Interface_Info.pdata_cmd<>nil then
    freemem(tempPC_Interface_Info.pdata_cmd);
  if tempPC_Interface_Info.pdata_dlbuff<>nil then
    freemem(tempPC_Interface_Info.pdata_dlbuff);
  if tempPC_Interface_Info<>nil then
    freemem(tempPC_Interface_Info);
end;

//发送获取phb内容的命令
procedure getPHBcontent(ctype:T_MFW_PHB_SELECT;cindex:byte;cbfunc:Pointer);
var  tempinfo:pPC_Interface_Info;
     tempcmd_phb:pPC_App_Cmd_PHB;
     tempbuffer_rx:PChar;
begin
  getmem(tempinfo,sizeof(TPC_Interface_Info));
  getmem(tempcmd_phb,sizeof(TPC_App_Cmd_PHB));
  getmem(tempbuffer_rx,SIZE_BUFFER);

 	fillchar(tempinfo^,sizeof(TPC_Interface_Info),#0);
 	fillchar(tempcmd_phb^,sizeof(TPC_App_Cmd_PHB),#0);
 	fillchar(tempbuffer_rx^,SIZE_BUFFER,#0);

	tempcmd_phb.cid1:= PC_AppCID1_PHB;
	tempcmd_phb.cid2:= PC_AppCID2_Read;
  tempcmd_phb.ctype:= ord(ctype);   //带上类型
 	tempcmd_phb.index:= cindex;//CurPHB_index;   //带上第几条记录

	tempinfo.flag:= PC_IF_FLAGS_DATADL;
	tempinfo.pdata_cmd:= PChar(tempcmd_phb);
	tempinfo.size_cmd:= sizeof(TPC_App_Cmd_PHB);

	tempinfo.pdata_dlbuff := tempbuffer_rx;
	tempinfo.size_dlbuff := SIZE_BUFFER;

	tempinfo.callback :=cbfunc ;

	pc_interface(tempinfo);
end;

⌨️ 快捷键说明

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