peterhowells

Simple Stopwatch

Apr 19th, 2022
975
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.06 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, Diagnostics, StdCtrls;
  8.  
  9. type
  10.   TfrmSW = class(TForm)
  11.     lblSW: TLabel;
  12.     btnStartStop: TButton;
  13.     btnReset: TButton;
  14.     procedure btnStartStopClick(Sender: TObject);
  15.     procedure btnResetClick(Sender: TObject);
  16.   private
  17.     { Private declarations }
  18.   public
  19.     { Public declarations }
  20.   end;
  21.  
  22. var
  23.   frmSW: TfrmSW;
  24.   sw: TStopWatch;
  25.   SWRunning: boolean;
  26.  
  27. implementation
  28.  
  29. {$R *.dfm}
  30.  
  31. procedure TfrmSW.btnResetClick(Sender: TObject);
  32. begin
  33.   if not SWRunning then lblSW.Caption := '00:00:00.000';
  34. end;
  35.  
  36. procedure TfrmSW.btnStartStopClick(Sender: TObject);
  37. begin
  38.   SWRunning := not SWRunning;
  39.   if SWRunning then sw := TStopwatch.StartNew;
  40.  
  41.   while(SWRunning) do
  42.   begin
  43.     lblSW.Caption := FormatDateTime('hh:nn:ss.zzz',sw.ElapsedMilliseconds/MSecsPerDay);
  44.  
  45.     // Handle any external events
  46.     Application.ProcessMessages;
  47.   end;
  48.  
  49.   // Set form DoubleBuffered property to True to prevent flickering
  50.  
  51. end;
  52.  
  53. end.
Advertisement
Add Comment
Please, Sign In to add comment