function IDInfo(const IDNO:String;var Birth:TDate;var Male:Boolean):Boolean;
var
lIDNO, BirthStr:String;
IDLen, i:Integer;
c:Char;
BirthYear, BirthMonth, BirthDay:Word;
begin
lIDNO:=Trim(IDNO);
IDLen:=Length(lIDNO);
Result:=False;
if (IDLen<>15) and (IDLen<>18) then
begin
Application.MessageBox('IDNO length error.',PChar(Application.Title),
mb_OK+mb_IconError);
exit;
end;
for i:=1 to IDLen do
begin
c:=lIDNO;
if (c<'0') or (c>'9') then
begin
Application.MessageBox('IDNO error number.',PChar(Application.Title),
mb_OK+mb_IconError);
exit;
end;
end;
if IDLen=15 then
begin
BirthStr:=Copy(lIDNO,7,6);
BirthStr:='19'+BirthStr;
end
else
BirthStr:=Copy(lIDNO,7,8);
BirthYear:=StrToInt(Copy(BirthStr,1,4));
BirthMonth:=StrToInt(Copy(BirthStr,5,2));
BirthDay:=StrToInt(Copy(BirthStr,7,2));
Try
Birth:=EncodeDate(BirthYear,BirthMonth,BirthDay);
Male:=((StrToInt(Copy(lIDNO,IDLen,1)) mod 2)=1);
Result:=True;
except
Application.MessageBox('IDNO error.',PChar(Application.Title),
mb_OK+mb_IconError);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Birth:TDate;
Male:Boolean;
begin
if IDInfo(Edit1.Text,Birth,Male) then
begin
Edit2.Text:=DateToStr(Birth);
if Male then
Edit3.Text:='Male'
else
Edit3.Text:='Female';
end
else
ShowMessage('Error');
end;