在Timer中添加代码如下:if (timetostr(time)>='8:33:00') and (timetostr(time)<'9:59:00') then
   begin
      BitBtn7.enabled:=false;
      BitBtn8.enabled:=false;
      BitBtn9.enabled:=true;
      BitBtn10.enabled:=false;
      RichEdit1.Enabled:=true;
      RichEdit1.Color:=clNone;
      RichEdit2.Enabled:=false;
      RichEdit2.Color:=clScrollBar;
   end;
现在问题便出来了,当时间每增加1秒,程序都要执行一道if语句,使得      RichEdit1.Enabled:=true;
      RichEdit1.Color:=clNone;不起作用,本来原来的目的是如果时间超过'8:33:00就可以在RichEdit1里面写内容的,结果现在是每增加一秒,程序就执行一道if语句,弄的来此语句无效,有没有比较好的解决办法?

解决方案 »

  1.   

    将以下这句
    if (timetostr(time)>='8:33:00') and (timetostr(time)<'9:59:00') then
    换成
    if (time>=strTotime('8:33:00')) and (time<strtotime('9:59:00')) then
      

  2.   

    譬如在判断时间值后再判断一下 if not richedit1.enabled then
      

  3.   

    其实有两个方法来解决该问题:
    1、可以在你的条件中加入timer1.interval=((9-8)*3600+(59-33)*60)*1000   (或者其他值)
       这样就不需要每1秒就变换了,即:
       if (timetostr(time)>='8:33:00') and (timetostr(time)<'9:59:00') then
       begin
          BitBtn7.enabled:=false;
          BitBtn8.enabled:=false;
          BitBtn9.enabled:=true;
          BitBtn10.enabled:=false;
          RichEdit1.Enabled:=true;
          RichEdit1.Color:=clNone;
          RichEdit2.Enabled:=false;
          RichEdit2.Color:=clScrollBar;
         timer1.interval=((9-8)*3600+(59-33)*60)*1000;
       end;
    2、可以再加一个timer2,这么写事件:if (timetostr(time)>='8:33:01') and (timetostr(time)<'9:58:59') then
        timer1.enabled:=false
    else timer1.enabled:=true;
      

  4.   

    if (time>=strtotime('8:33:01')) and (time<strtotime('9:58:59')) then
    你这里不是比较的时间大小了是两个字符串比较是不可能实现对时的比较的,,,,试试这个吧