您现在的位置是:首页-> 米鼠技术 ->Delphi中进行延时的4种方法

Delphi中进行延时的4种方法

  1、挂起,不占CPU

Color=#cccccc cellSpacing=0 cellPadding=1 width="80%" align=center bgColor=#ffffff border=1 heihgt="">

 sleep


        2、不挂起,占cpu

  procedure Delay(msecs:integer);
        var
        FirstTickCount:longint;
        begin
        FirstTickCount:=GetTickCount;
        repeat
        Application.ProcessMessages;
        until ((GetTickCount-FirstTickCount)
<font size="3">&gt;</font>= Longint(msecs));
        end;


               3、定时器

   procedure timerfun(handle:Thandle;msg:word;identer:word;dwtime:longword);stdcall;
        begin
        showmessage('到点了');
        killtimer(handle,identer);//关闭定时器
        end;
        //其中的identer是定时器的句柄
        procedure TForm1.Button1Click(Sender: TObject);
        var
        identer:integer;
        begin
           identer:=settimer(0,0,2000,@timerfun);
           if identer=0 then exit; //定时器没有创建成功。
        end;


              4、不占CPU不挂起

 function TForm1.HaveSigned(MaxWaitTime: Cardinal): Boolean;
        var   I:Integer;
        var   WaitedTime:Cardinal;
        begin
                  WaitedTime:=0;
                  while      (WaitedTime
<font size="3">&lt;</font>MaxWaitTime)   do
                  begin
                          SleepEx(100,False);
                          Inc(WaitedTime,100);
                          Application.ProcessMessages ;
                  end
        end;


热点文章
最新项目
相关文章 最新文章