时间定时问题,我想在一条语句执行之后定时一定的时间后再执行下一条语句,如
i:=i+1;
定时一定的时间(单位为毫秒)的语句
i:=0;请问除了使用Sleep方法之外还有其它什么办法,

解决方案 »

  1.   

    可以用现实的时间来想你这个问题如:Formatdetatime('yyyy-mm-dd',now)等,这比你用Add的方法准确!!!
      

  2.   

    上面搞错了!!!应该是DecodeTime,或者EncodeTime;
      

  3.   

    for (int i=0; i<10000000; i++)
    {
       if ()
       {
       }
    }效率有点底下,还不如用Sleep
      

  4.   

    不如放个定时器:(timer控件),在定时器中判断时间:
    i:=i+1;
    定时器打开
    i:=0;上面的方法可以,但如果你需要精确时间的花就不可以了,因为各个计算机CPU的频率等原因所以上面的方法时间不准
      

  5.   

    //摘自网络,延时
     // 1. Delay 
    procedure Delay(dwMilliseconds: Longint);variStart, iStop: DWORD;beginiStart := GetTickCount;repeatiStop := GetTickCount;Application.ProcessMessages;until (iStop - iStart) >= dwMilliseconds;end;// 2. Delay: with APIprocedure Delay(msecs: Longint);vartargettime: Longint;Msg: TMsg;begintargettime := GetTickCount + msecs;while targettime < GetTickCount doif PeekMessage(Msg, 0, 0, 0, PM_REMOVE) thenbeginTranslateMessage(Msg);DispatchMessage(Msg);end;end;{Note:The elapsed time is stored as a DWORD value.Therefore, the time will wrap around to zero if the system isrun continuously for 49.7 days.}// 3. Sleep{The Sleep function suspends the execution of the currentthread for a specified interval.}Sleep(dwMilliseconds: Word); // 4. Combined Delay{Including the Sleep in the loop prevents the app from hogging100% of the CPU for doing practically nothing but running around the loop.}procedure PauseFunc(delay: DWORD);varlTicks: DWORD;beginlTicks := GetTickCount + delay;repeatSleep(100);Application.ProcessMessages;until (lTicks <= GetTickCount) or Application.Terminated;end;还可以用SleepEx函数。