我在写一个身份证验证程序,怎么在执行下面代码时,我输入18位身份证,它会执行15位下面的程序呢???
function TForm1.cuowu(sbh: string): integer;
//0:正确 1:位数错误 2:日期错误 3:年龄错误
begin
cuowu:=0;
if (length(trim(sbh))=15) or (length(trim(sbh))=18) then
begin
try
if length(trim(sbh))=15 then
begin
strtodate('19'+copy(sbh,7,2)+'-'+copy(sbh,9,2)+'-'+copy(sbh,11,2));//在这里没加begin..end时会执行这句????
end;
if length(trim(sbh))=18 then
strtodate(copy(sbh,7,4)+'-'+copy(sbh,11,2)+'-'+copy(sbh,13,2));
cuowu:=0;
except
cuowu:=2;
end;
if length(trim(sbh))=15 then
begin
if (yearof(DATE)-strtoint('19'+copy(trim(sbh),7,2))<15) or (yearof(DATE)-strtoint('19'+copy(trim(sbh),7,2))>200) then
cuowu:=3;
end;
if length(trim(sbh))=18 then
begin
if (yearof(DATE)-strtoint(copy(trim(sbh),7,4))<15) or (yearof(DATE)-strtoint(copy(trim(sbh),7,4))>120) then
cuowu:=3;
end;
end
else
cuowu:=1;//我在这没加begin..end时也要执行这句???
end;
function TForm1.cuowu(sbh: string): integer;
//0:正确 1:位数错误 2:日期错误 3:年龄错误
begin
cuowu:=0;
if (length(trim(sbh))=15) or (length(trim(sbh))=18) then
begin
try
if length(trim(sbh))=15 then
begin
strtodate('19'+copy(sbh,7,2)+'-'+copy(sbh,9,2)+'-'+copy(sbh,11,2));//在这里没加begin..end时会执行这句????
end;
if length(trim(sbh))=18 then
strtodate(copy(sbh,7,4)+'-'+copy(sbh,11,2)+'-'+copy(sbh,13,2));
cuowu:=0;
except
cuowu:=2;
end;
if length(trim(sbh))=15 then
begin
if (yearof(DATE)-strtoint('19'+copy(trim(sbh),7,2))<15) or (yearof(DATE)-strtoint('19'+copy(trim(sbh),7,2))>200) then
cuowu:=3;
end;
if length(trim(sbh))=18 then
begin
if (yearof(DATE)-strtoint(copy(trim(sbh),7,4))<15) or (yearof(DATE)-strtoint(copy(trim(sbh),7,4))>120) then
cuowu:=3;
end;
end
else
cuowu:=1;//我在这没加begin..end时也要执行这句???
end;
15位下程序是什么意思?
cuowu:=1;//我在这没加begin..end时也要执行这句??? 这里加不加begin end都是一样的啊
樓主,你的delphi是不是有問題啊。
strtodate('19'+copy(sbh,7,2)+'-'+copy(sbh,9,2)+'-'+copy(sbh,11,2));输入18位不应该有问题的。难道真是我delphi有问题???
另外,你可以将优化关闭(Project options->copmiler->optimization前的勾)
http://topic.csdn.net/u/20080912/09/de7ecae2-ef07-4c3b-955e-f251a24925f5.html