在做一个财务方面的程序,需要强制日期为30天,用datetimepicker不行,因为有些天没有30天,就无法输入2011-02-30 这样了,所以只能用MaskEdit,现在格式已经控制好只能输入数字了,但要怎么判断用户输入的数字是我指定值之间的呢(比如月年都是正常的,只有日需要是30天,不准输入大于30的数值)?我下面写的代码还是报错频繁,而且用try都控制不了,不知道还有什么更好的方法么,请大家指点下小弟。----------
财务小管家
----------
Invalid input value. Use escape key to abandon changes.
----------
确定
----------代码:
var
riqi:string;
n,y,r:string;
begin
try
n:=copy(str,1,pos('-',str)-1); //年 riqi:=copy(str,pos('-',str)+1,Maxint);
y:=copy(riqi,1,pos('-',riqi)-1); //月 riqi:=copy(str,pos('-',str)+1,Maxint);
r:=copy(riqi,pos('-',riqi)+1,Maxint); //日 if ''=n then nian:=0 else nian:=StrToInt(n); //取年
if ''=y then yue:=0 else yue:=strToint(y); //取月
if ''=r then ri:=0 else ri:=strToInt(r); //取天if (nian>2030) or (nian<2010) or (yue=0) or (yue>12) or (ri=0) or (ri>30) then
begin
ShowMessage('日期填写错误!太大或太小!');
exit;
end;
except
ShowMessage('日期填写错误!');
exit;
end;
财务小管家
----------
Invalid input value. Use escape key to abandon changes.
----------
确定
----------代码:
var
riqi:string;
n,y,r:string;
begin
try
n:=copy(str,1,pos('-',str)-1); //年 riqi:=copy(str,pos('-',str)+1,Maxint);
y:=copy(riqi,1,pos('-',riqi)-1); //月 riqi:=copy(str,pos('-',str)+1,Maxint);
r:=copy(riqi,pos('-',riqi)+1,Maxint); //日 if ''=n then nian:=0 else nian:=StrToInt(n); //取年
if ''=y then yue:=0 else yue:=strToint(y); //取月
if ''=r then ri:=0 else ri:=strToInt(r); //取天if (nian>2030) or (nian<2010) or (yue=0) or (yue>12) or (ri=0) or (ri>30) then
begin
ShowMessage('日期填写错误!太大或太小!');
exit;
end;
except
ShowMessage('日期填写错误!');
exit;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货