首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

总报错,请一下

2013-12-28 
总报错,请高手指点一下。procedure TForm1.Button1Click(Sender: TObject) varyear,month,days:integerbl

总报错,请高手指点一下。
总报错,请一下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,  是 . 不是 , 

[解决办法]
是啥是啊。。。
copy函数的第一个参数是一个字符串, 你把maskedit1控件放进去做什么
都跟你说了把

 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;

热点排行