procedure TfrmMain.checkDateEX(edt: Tmaskedit);
var
iyear, imonth, iday: word;
begin
if edt.Text <> ' - - ' then
begin
iyear := strToint(copy(edt.Text, 1, 4));
imonth := strToint(copy(edt.Text, 6, 2));
iday := strToInt(copy(edt.Text, 9, 2));
if (iyear < 1930) then
begin
showmessage('非法日期,请重新输入!');
edt.SetFocus;
exit;
end
else
begin
if (imonth < 1) or (imonth > 12) then
begin
showmessage('非法日期,请重新输入!');
edt.SetFocus;
exit;
end;
if imonth = 2 then
begin
if ((iyear mod 4) = 0) or ((iyear mod 100) = 0) then
begin
if (iday > 29) or (iday < 1) then
begin
showmessage('非法日期,请重新输入!');
edt.SetFocus;
exit;
end;
end
else
begin
if (iday > 28) or (iday < 1) then
begin
showmessage('非法日期,请重新输入!');
edt.SetFocus;
exit;
end;
end;
end
else if (imonth = 1) or (imonth = 3) or (imonth = 5) or (imonth = 7) or
(imonth = 8) or (imonth = 10) or (imonth = 12) then
begin
if (iday > 31) or (iday < 1) then
begin
showmessage('非法日期,请重新输入!');
edt.SetFocus;
exit;
end;
end
else
begin
if (iday > 30) or (iday < 1) then
begin
showmessage('非法日期,请重新输入!');
edt.SetFocus;
exit;
end;
end;
end;
end;
end;
博客给出了一段Delphi代码,定义了一个名为checkDateEX的过程,用于检查输入日期的合法性。代码会对年、月、日进行判断,若日期不合法,如年份小于1930、月份不在1 - 12之间等,会提示重新输入并将焦点设置到输入框。

2257

被折叠的 条评论
为什么被折叠?



