关于日期的格式及判断输入!(50分)

  • 主题发起人 主题发起人 yzy25
  • 开始时间 开始时间
Y

yzy25

Unregistered / Unconfirmed
GUEST, unregistred user!
我已经作到使用户只能在日期栏输入数字但我想做进一步改进!设想如下
用户只能输入0<month<=31的数,若输入其他不在范围的则输不进去!
procedure onedit1exit(...)
begin
if strtoint(edit1.text)>31 then
begin
edit1.text:='';
edit1.setfocus;
end;
else
setnextfocus;
end;
不知可不可以望各位大虾指教!
 
可以自然可以,不过干吗不用datetimepicker?
而且你这样要作的工作还很多,比如判断此月份是28天?29天?30天还是31天。光
判断是否小于等于31并不能说明输入正确
 
to up //可是datatimepicker太不好用了,用户输入起来很麻烦!
 
可是datatimepicker太不好用了,用户输入起来很麻烦-----我看不见得!
你可以给你的客户培训怎么用阿
 
const
NormalDays: array[1..12] of Integer = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
LeapDays: array[1..12] of Integer = (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

procedue tform1.editdaychange(sender: tobject);
var
iday: integer;
begin
try
iday := strtoint(editday.text);
if isleapyear(yearvalue) then
begin
if iday > leapdays[monthvalue] then
begin
iday := leapdays[monthvalue];
editday.selectall;
end;
end
else
begin
if iday > Normaldays[monthvalue] then
begin
iday := normaldays[monthvalue];
editday.selectall;
end;
end;
except
end
end;

 
可以根据年月进行精确判断,特别是有没有 2 月 29日

procedure onedit1exit(...)
begin
if strtoint(edit1.text)>31 then //进行精确判断
begin
edit1.text:=''; //可以不清,反正通不过
edit1.setfocus;
end;
else
setnextfocus; //多此一句,不需要的。
end;
 
你可以看看以下贴中我的意见:

http://www.delphibbs.com/delphibbs/dispq.asp?lid=1308956
 
多人接受答案了。
 
后退
顶部