unit uDemo;

interface

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

type
  TfrmDemo = class(TForm)
    ApSimpleStopwatch: TApSimpleStopwatch;
    btnToggle: TButton;
    btnReset: TButton;
    mTime: TMemo;
    chkUseHighResolution: TCheckBox;
    procedure FormCreate(Sender: TObject);
    procedure btnToggleClick(Sender: TObject);
    procedure btnResetClick(Sender: TObject);
    procedure chkUseHighResolutionClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  frmDemo: TfrmDemo;

implementation

{$R *.dfm}

{--------------------------------------------------------------------------------------------------
  Set some options on startup.
 --------------------------------------------------------------------------------------------------}
procedure TfrmDemo.FormCreate(Sender: TObject);
begin
  mTime.Clear();
  btnReset.Enabled := False;
  mTime.Lines.Add('HighResolution: ' + BoolToStr(ApSimpleStopwatch.HighResolution, True));
  mTime.Lines.Add('---------------------');
  chkUseHighResolution.Checked := ApSimpleStopwatch.UseHighResolution;
end;

{--------------------------------------------------------------------------------------------------
  Toggles the timer and displays the elapsed time (in milliseconds) between a start and stop.
 --------------------------------------------------------------------------------------------------}
procedure TfrmDemo.btnToggleClick(Sender: TObject);
begin
  btnReset.Enabled := True;
  if (btnToggle.Caption = 'Start') then
  begin
    ApSimpleStopwatch.Start();
    btnToggle.Caption := 'Stop';
  end
  else begin
    btnToggle.Caption := 'Start';
    ApSimpleStopwatch.Stop();
    mTime.Lines.Add(IntToStr(ApSimpleStopwatch.GetElapsedMilliseconds()) + 'ms');
  end;
end;

{--------------------------------------------------------------------------------------------------
  Resets timer.
 --------------------------------------------------------------------------------------------------}
procedure TfrmDemo.btnResetClick(Sender: TObject);
begin
  btnReset.Enabled := False;
  btnToggle.Caption := 'Start';
  ApSimpleStopwatch.Reset();
end;  

{--------------------------------------------------------------------------------------------------
  
 --------------------------------------------------------------------------------------------------}
procedure TfrmDemo.chkUseHighResolutionClick(Sender: TObject);
begin
  if (ApSimpleStopwatch.Running) then
    btnReset.Click();
  ApSimpleStopwatch.UseHighResolution := chkUseHighResolution.Checked;
end;


end.

