function GetAgeByIdNo(const PersonalID:string):integer;
var
m_DBirthday:TDatetime;
year1,year2,month1,month2,day1,day2 : word;
iAge : smallint;
begin
result:=0;
if (Length(PersonalID)<>15) and (Length(PersonalID)<>18) then
begin
Prompt('身份证位数不对,请重新输入!');
Exit;
end;
if PersonalID <> '' then
begin
if Length(PersonalID) = 15 then
m_DBirthday:= strtodatetime('19' + Copy(PersonalID,7,2) + '-' + Copy(PersonalID,9,2) + '-' + Copy(PersonalID,11,2))
else
m_DBirthday:= strtodatetime(Copy(PersonalID,7,4)+ '-' + Copy(PersonalID,11,2) + '-'+ Copy(PersonalID,13,2))
end;
DecodeDate(Now, year1, month1, day1);
DecodeDate(m_DBirthday, year2, month2, day2);
iAge := Year1 - Year2
result:=iAge;
end;