Delphi 延迟函数

2019-10-3111:51:56来源:aBung 评论 290 views

延迟函数:方法一

procedure delay(msecs:integer);
var
  Tick: DWord; 
  Event: THandle; 
begin
  Event := CreateEvent(nil, False, False, nil); 
  try
    Tick := GetTickCount + DWord(msecs); 
    while (msecs > 0) and (MsgWaitForMultipleObjects(1, Event, False, msecs, QS_ALLINPUT) <> WAIT_TIMEOUT) do
    begin
      Application.ProcessMessages; 
      msecs := Tick - GetTickcount; 
    end; 
  finally
    CloseHandle(Event); 
end;

延迟函数:方法二

procedure Delay(dwMilliseconds:DWORD);//Longint
var
iStart,iStop:DWORD;
begin
    iStart :=   GetTickCount;
    repeat
    iStop  :=   GetTickCount;
    Application.ProcessMessages;
    until (iStop  -  iStart) >= dwMilliseconds;
end;

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: