timer.pas

来自「Source code Delphi FTP-server」· PAS 代码 · 共 50 行

PAS
50
字号
{$A+,B-,C+,D+,E-,F-,G+,H-,I-,J+,K-,L+,M-,N+,O-,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}
unit Timer;

{-----------------------------------------------------------------}
{ Timer. To create calibrated timeouts (1/10 sec).                }
{ 11/19/1999 Drt.                                                 }
{-----------------------------------------------------------------}

interface

uses
  Windows, Classes;

type
 pbool = ^boolean;

 TTimeout = class(TThread)
 public
   Flag : pbool;
   Timeout : longint;
   constructor create(ATimeout : longint; AFlag : pbool);
 private
   procedure execute; override;
   end;

implementation

constructor TTimeout.create(ATimeout : longint; AFlag : pbool);
begin
inherited create(true);
FreeOnTerminate:=true;
Flag:=AFlag;
Timeout:=ATimeout;
Flag^:=false;
resume;
end;

procedure TTimeout.execute;
begin
while ((Timeout > 0) or (Timeout < 0)) and not terminated do
  begin
  sleep(100);
  if Timeout > 0 then dec(Timeout);
  end;
Flag^:=true;
if not terminated then terminate;
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?