Recent Posts

Selamat datang di Coding Delphi Land Weblog kumpulan source code pemogram delphi

(Bukan maksud untuk menggurui tetapi marilah kita berbagi ilmu tuk perkembangan kemajuan teknologi kita

Selasa, 26 September 2017

Timer



unit Timers_Unit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Exit: TButton;
    Label1: TLabel;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure ExitClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

{our timer callback prototype}
procedure TimerProc(hWnd: HWND; uMsg: UINT; idEvent: UINT; Time: DWORD);stdcall;

var
  Form1: TForm1;
  DemoCounter: Integer;   // a counter to demonstrate that a timer is running

const
  EXAMPLETIMER = 1;       // a timer identifier

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  Tick: DWORD;    // holds the number of milliseconds
begin
  {get the number of milliseconds since Windows was started}
  Tick:= GetTickCount;

  {display the number of milliseconds}
  Label1.Caption := 'Number of Milliseconds: ' + IntToStr(Tick);
  Label2.Caption := '';
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  {reset our counter}
  DemoCounter:= 0;

  {create a timer to fire once per second}
  SetTimer(Form1.Handle, // handle of window for timer messages
           EXAMPLETIMER, // timer identifier
           1000,        // fire every 1000 milliseconds
           @TimerProc        // address of timer procedure
           );
end;

{this function is run every time EXAMPLETIMER fires}
procedure TimerProc(hWnd: HWND; uMsg: UINT; idEvent: UINT; Time: DWORD);
begin
  {display a message to show that the timer is running}
  Form1.Label1.Caption := 'Timer1 is Now Running: ' + IntToStr(DemoCounter);
  Form1.Label2.Caption := '';

  {increment a counter to show that the timer is running}
  Inc(DemoCounter);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  {remove our example timer}
  KillTimer(Form1.Handle, // handle of window that installed timer
            EXAMPLETIMER   // timer identifier
            );

   {clear the caption}
   Label1.Caption := '';
   Label2.Caption := '';
end;

procedure TForm1.Button4Click(Sender: TObject);
var
  PerformanceCount: TLargeInteger;
begin
  {if there is a high resolution performance counter in the hardware...}
  if QueryPerformanceCounter(PerformanceCount) then
    begin
      {...display its current counter...}
     // Label1.Caption := 'Performance Counter Present';
      //Label2.Caption := FloatToStr(PerformanceCount.QuadPart);
    end
  else
    begin
      {...or display a message}
     // Label1.Caption := 'Performance Counter Not Present';
     // Label2.Caption := '';
    end;
end;

procedure TForm1.Button5Click(Sender: TObject);
var
  PerformanceFrequency: TLargeInteger;
begin
  {if there is a high resolution performance counter in the hardware...}
  if QueryPerformanceFrequency(PerformanceFrequency) then
    begin
      {...display its frequency...}
    //  Label1.Caption := 'Performance Frequency Present';
    //  Label2.Caption := FloatToStr(PerformanceFrequency.QuadPart);
    end
  else
    begin
      {...or display a message}
   //   Label1.Caption := 'Performance Frequency Not Present';
    //  Label2.Caption := '';
    end;
end;

procedure TForm1.ExitClick(Sender: TObject);
begin
  Form1.Close;
end;


end.

0 komentar:

Posting Komentar