deilphi 身份证问题求助
如form1上有edit1.text 输入身份证 330323198603032811 这个
怎样做到当上面输入完后,系统自动在 edit2.text 上产生如 1986.03.28
和edit3.text 25岁 edit4.text 男 edit1,edit2,和edit4都这字符型的,
edit3 是整型的
如form1上有edit1.text 输入身份证 330323198603032811 这个
怎样做到当上面输入完后,系统自动在 edit2.text 上产生如 1986.03.28
和edit3.text 25岁 edit4.text 男 edit1,edit2,和edit4都这字符型的,
edit3 是整型的
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);
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);
后者丢失焦点
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)))';
这样计算年龄怎么会出错啊
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;