emulatetimeru.pas
来自「Delphi Win32核心API参考光盘源码 本书包含了常用的Windows」· PAS 代码 · 共 71 行
PAS
71 行
unit EmulateTimerU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Running: Boolean; // the loop control variable
implementation
{$R *.DFM}
procedure FlashLoop;
var
StartTick: DWORD; // holds the start time
begin
{get the current tick count}
StartTick := GetTickCount;
{if the loop is still running...}
while Running do
begin
{...check the elapsed time. if a second has passed...}
if (GetTickCount-StartTick)>1000 then
begin
{...update the label on the form}
Form1.Label1.Visible := not Form1.Label1.Visible;
{reinitialize the start time for the next round}
StartTick := GetTickCount;
end;
{this is required so the loop doesn't lock up the machine}
Application.ProcessMessages;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
{set the loop control variable...}
Running := TRUE;
{...and start the loop}
FlashLoop;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
{the loop control variable must be set to FALSE
so the loop will exit and the program can close}
Running := FALSE;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?