deilphi 身份证问题求助
如form1上有edit1.text  输入身份证 330323198603032811  这个
怎样做到当上面输入完后,系统自动在 edit2.text 上产生如 1986.03.28
和edit3.text 25岁   edit4.text 男 edit1,edit2,和edit4都这字符型的,
edit3 是整型的

解决方案 »

  1.   

    还要注意新旧身份证的生日信息的位置有所不同
    if length(edit1.text)=18 then
      edit2.text:=copy(edit1.text,7,4)+'.'+copy(edit1.text,12,2)+'.'+copy(edit1.text,15,2)
    else
      edit2.text:='19'+copy(edit1.text,7,2)+'.'+copy(edit1.text,10,2)+'.'+copy(edit1.text,13,2);
      

  2.   

    要改为:
    if length(edit1.text)=18 then
      edit2.text:=copy(edit1.text,7,4)+'.'+copy(edit1.text,11,2)+'.'+copy(edit1.text,13,2)
    else
      edit2.text:='19'+copy(edit1.text,7,2)+'.'+copy(edit1.text,9,2)+'.'+copy(edit1.text,11,2);
      

  3.   

    你可以相应keypress 实现,当用户 按下回车键就开始分析
    后者丢失焦点 
      

  4.   

    http://blog.csdn.net/wr960204/archive/2007/09/19/1791207.aspx
      

  5.   

    if length(edit1.text)=18 then
      edit2.text:=copy(edit1.text,7,4)+'.'+copy(edit1.text,11,2)+'.'+copy(edit1.text,13,2)
    else
      edit2.text:='19'+copy(edit1.text,7,2)+'.'+copy(edit1.text,9,2)+'.'+copy(edit1.text,11,2); edit3.Text:='convert(int,year(getdate()))-convert(int,year(convert(datetime,edit14.text)))';
    这样计算年龄怎么会出错啊
      

  6.   

    给你一个自编的函数:
    function CarToBirthday(S:string):String;   //  由身份证号得到出身年月
    var i,l:integer;
        s1,s2,s3:string;
    begin
      Result := '';
      l:=length(S);
      if (L=15) or (L=18) then
      begin
        if l=15
        then begin
          s1:=Copy(S,7,2);
          S1:='19'+s1;
          s2:=Copy(S,9,2);
          s3:=Copy(S,11,2);
        end
        else begin
          s1:=Copy(S,7,4);
          s2:=Copy(S,11,2);
          s3:=Copy(S,13,2);
        end;
        if (StrToInt(S2)>0) and (StrToInt(S2)<=12) and
           (StrToInt(S3)>0) and (StrToInt(S2)<=31) then
          Result:=S1+'-'+S2+'-'+S3;
      end;
    end;