总报错,请高手指点一下。
procedure TForm1.Button1Click(Sender: TObject);
var
year,month,days:integer;
bl:boolean;
begin
//判断年份是否有空字符或月份全部为空格字符
if (pos('',copy(maskedit1.Text,1,4))=0) and (copy(maskedit1.Text,5,2)<> ' ')
then
begin
year:=strtoint(copy(maskedit1.Text,1,4));//取年份
bl:=(year mod 400=0) or (year mod 100 <>0 ) and (year mod 4 =0);
if bl
then
label2.caption:=copy(maskedit1.text,1,4)+' 是闰年 '
else
label2.Caption:=copy(maskedit1.Text,1,4)+' 是平年 ';
if copy(maskedit1.Text,6,1)=''//若月份第二位是空,则只取第一位
then month:=strtoint(copy(maskedit1,text,5,1))
else month:=strtoint(copy(maskedit1.text,5,2));
case month of
1,3,5,7,8,10,12:days:=31;
4,6,9,11:days:=30;
2:if bl then days:=29 else days:=28;
else
begin
month:=12;
days:=31;
end;
end;
label3.caption:=inttostr(month)+'月有 '+inttostr(days)+'天 ';
end
else
begin
showmessage('年份不能有空,月份不能全空,请重新输入!');
maskedit1.setfocus;
end;
end;
end.
F9之后,一真显示错误,,但没看出来错在哪里。。。
[解决办法]
then month:=strtoint(copy(maskedit1,text,5,1)) //maskedit1.text, 是 . 不是 ,
then month:=strtoint(copy(maskedit1,text,5,1)) //maskedit1,text 改 maskedit1.text
if copy(maskedit1.Text,6,1)=''//若月份第二位是空,则只取第一位
then month:=strtoint(copy(maskedit1,text,5,1)) // 看到了没有,是 maskedit1.text,而不是 ,
else month:=strtoint(copy(maskedit1.text,5,2));
case month of
1,3,5,7,8,10,12:days:=31;
4,6,9,11:days:=30;