当前位置: 首页 > news >正文

Delphi5实现身份证检验(DLL版)

效果图

在这里插入图片描述

身份证行政区划分代码

在这里插入图片描述

识别归属地需要行政区划分,都在data.txt文档里面了。

在这里插入图片描述

最后一位校验码

根据上面的原理编写程序即可。

{这个函数计算最后一位检验码是否正确,ID是18位身份证号字符串,结果返回字符串}
function IDcheck(ID:string):string;
const//权重W:array[1..17] of Integer = (7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2);//最后一位校验码A:array[0..10] of Char = ('1','0','x','9','8','7','6','5','4','3','2');
varnewID:string;j,i,S:Integer;
beginnewID:=ID;S:=0;for i:=1 to 17 dobegin//求加权因子的乘积。j:=strtoint(newID[i])*W[i];//求和S:=S+j;end;//求模S:=S mod 11;//查表Result:=A[S];
end;

识别出生日期

传入的身份证号就有出生日期,直接截取相应字符串就好。有趣的是,使用到了参数传递,直接修改变量的值。

{年月日这三个是通过 var 关键字传递的变量,
意味着它们在函数内部被修改后,其变化会反映到调用函数时的变量上。}
function IDcard(IDNo:string;var year,month,day:Integer):Boolean;stdcall;
beginif Length(IDNo)<>18 thenbeginyear:=-1;Result:=False;end//判断最后一位检验码是否正确else if IDcheck(IDNo)=Copy(IDNo,18,1) thenbegin//将年月日截取出来year:=StrToInt(Copy(IDNo,7,4));month:=StrToInt(Copy(IDNo,11,2));day:=StrToInt(Copy(IDNo,13,2));Result:=True;endelseResult:=False;
end;

识别性别

原理同上表,偶数为女生,奇数为男生。

{检查性别}
function sexcheck(IDNo:string):string;stdcall;
varstr:string;
beginstr:=Copy(IDNo,17,1);if StrToInt(str) mod 2 =1 thenResult:='男'elseResult:='女';
end;

识别归属地

需要查data.txt,这个文件已经上传到CSDN了,上面有链接,可以自取。

{判断归属地}
function Addcheck(IDNo:string):string;stdcall;
varF1:TextFile;str_temp,str1,str2,str3,str4:string;begin//AssignFile 函数是用于将文件变量与磁盘上的文件关联起来的。//这是进行文件操作(如读写文件)的第一步。AssignFile(F1,'data.txt');Reset(F1);  // 尝试以读取模式打开文件tryReadln(F1,str1);  //将F1的内容第一行读到str1while not Eof(F1) do    // 检查文件是否成功打开beginstr_temp:=str1;str1:=Copy(str1,1,6);  //截取前六位行政区号//截取前两位判断省份if str1=Copy(IDNo,1,2)+'0000' thenbeginstr2:=Trim(Copy(str_temp,7,40));end;//判断市if str1=Copy(IDNo,1,4)+'00' thenbeginstr3:=Trim(Copy(str_temp,7,40));end;//判断县if str1=Copy(IDNo,1,6) thenbeginstr4:=Trim(Copy(str_temp,7,40));result:=str2+str3+str4;Exit;end;Readln(F1,str1);end;    Result:='输入不合法,请重新输入!';finallyCloseFile(F1);end;
end;

完整DLL文件

library Project1;
{这是动态链接库了}{ Important note about DLL memory management: ShareMem must be thefirst unit in your library's USES clause AND your project's (selectProject-View Source) USES clause if your DLL exports any procedures orfunctions that pass strings as parameters or function results. Thisapplies to all strings passed to and from your DLL--even those thatare nested in records and classes. ShareMem is the interface unit tothe BORLNDMM.DLL shared memory manager, which must be deployed alongwith your DLL. To avoid using BORLNDMM.DLL, pass string informationusing PChar or ShortString parameters. }usesSysUtils,Classes,Windows,Controls,Messages,Dialogs;{$R *.RES}{第一步:编写DLL文件的函数,加上stdcall,表明函数被外部调用}{这个函数计算最后一位检验码是否正确,ID是18位身份证号字符串,结果返回字符串}
function IDcheck(ID:string):string;
const//权重W:array[1..17] of Integer = (7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2);//最后一位校验码A:array[0..10] of Char = ('1','0','x','9','8','7','6','5','4','3','2');
varnewID:string;j,i,S:Integer;
beginnewID:=ID;S:=0;for i:=1 to 17 dobegin//求加权因子的乘积。j:=strtoint(newID[i])*W[i];//求和S:=S+j;end;//求模S:=S mod 11;//查表Result:=A[S];
end;{年月日这三个是通过 var 关键字传递的变量,
意味着它们在函数内部被修改后,其变化会反映到调用函数时的变量上。}
function IDcard(IDNo:string;var year,month,day:Integer):Boolean;stdcall;
beginif Length(IDNo)<>18 thenbeginyear:=-1;Result:=False;end//判断最后一位检验码是否正确else if IDcheck(IDNo)=Copy(IDNo,18,1) thenbegin//将年月日截取出来year:=StrToInt(Copy(IDNo,7,4));month:=StrToInt(Copy(IDNo,11,2));day:=StrToInt(Copy(IDNo,13,2));Result:=True;endelseResult:=False;
end;{检查性别}
function sexcheck(IDNo:string):string;stdcall;
varstr:string;
beginstr:=Copy(IDNo,17,1);if StrToInt(str) mod 2 =1 thenResult:='男'elseResult:='女';
end;{判断归属地}
function Addcheck(IDNo:string):string;stdcall;
varF1:TextFile;str_temp,str1,str2,str3,str4:string;begin//AssignFile 函数是用于将文件变量与磁盘上的文件关联起来的。//这是进行文件操作(如读写文件)的第一步。AssignFile(F1,'data.txt');Reset(F1);  // 尝试以读取模式打开文件tryReadln(F1,str1);  //将F1的内容第一行读到str1while not Eof(F1) do    // 检查文件是否成功打开beginstr_temp:=str1;str1:=Copy(str1,1,6);  //截取前六位行政区号//截取前两位判断省份if str1=Copy(IDNo,1,2)+'0000' thenbeginstr2:=Trim(Copy(str_temp,7,40));end;//判断市if str1=Copy(IDNo,1,4)+'00' thenbeginstr3:=Trim(Copy(str_temp,7,40));end;//判断县if str1=Copy(IDNo,1,6) thenbeginstr4:=Trim(Copy(str_temp,7,40));result:=str2+str3+str4;Exit;end;Readln(F1,str1);end;Result:='输入不合法,请重新输入!';finallyCloseFile(F1);end;
end;{第二步:导出函数}
exportsIDcard,sexcheck,Addcheck;begin
end.

完整代码

放在CSDN了,可以自取。

在这里插入图片描述

http://www.lryc.cn/news/417304.html

相关文章:

  • linux下的C++程序
  • selfAttention 中的dk到底是什么
  • 安装MongoDB UI客户端工具:mongodb-compass-1.40.2-win32-x64.msi
  • 一行命令搞定内网穿透
  • C语言——扫雷游戏
  • 【LLM】-16-评估LLM-与标准答案的差距
  • WeNet 2.0:更高效的端到端语音识别工具包
  • 阿里大模型调用 = 》通义千问大语言模型
  • idea使用free流程,2024idea免费使用
  • 算法_链表专题---持续更新
  • 在Windows MFC\C++编程中,如何使用OnCopyData函数
  • 【Qt】项目代码
  • MySQL中常用工具
  • 关于儿童编程语言
  • [io]进程间通信 -信号函数 —信号处理过程
  • RoboDK的插件
  • List<HashMap<String, Object>>排序
  • 【大数据】探索大数据基础知识:定义、特征与生态系统
  • 营销材料翻译质量对销售渠道的影响
  • centos7.9安装k8s 1.3
  • 【第七节】python多线程及网络编程
  • Linux Shell编程--变量
  • 软文写作必须掌握的技巧有哪些?
  • 探索灵办AI:智能办公的好帮手
  • gin-vue-admin框架遇到AxiosError:Network Error怎么解决?
  • 作业zzz
  • python 空list如何表示
  • C++ const、constexpr与consteval作用与区别
  • solidity 数学和密码学函数
  • opencv-图像透视变换