Ignore:
Timestamp:
Jun 19, 2024, 11:15:44 PM (5 months ago)
Author:
chronos
Message:
  • Modified: Updated Common package.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/StopWatch.pas

    r43 r315  
    55
    66uses
    7   {$IFDEF Windows}Windows,{$ENDIF}
     7  {$IFDEF WINDOWS}Windows,{$ENDIF}
    88  SysUtils, DateUtils;
    99
     
    1313  TStopWatch = class
    1414  private
    15     fFrequency : TLargeInteger;
    16     fIsRunning: Boolean;
    17     fIsHighResolution: Boolean;
    18     fStartCount, fStopCount : TLargeInteger;
    19     procedure SetTickStamp(var lInt : TLargeInteger) ;
     15    FFrequency: TLargeInteger;
     16    FIsRunning: Boolean;
     17    FIsHighResolution: Boolean;
     18    FStartCount, fStopCount: TLargeInteger;
     19    procedure SetTickStamp(var Value: TLargeInteger);
    2020    function GetElapsedTicks: TLargeInteger;
    2121    function GetElapsedMiliseconds: TLargeInteger;
    2222    function GetElapsed: string;
    2323  public
    24     constructor Create(const startOnCreate : Boolean = False) ;
     24    constructor Create(const StartOnCreate: Boolean = False) ;
    2525    procedure Start;
    2626    procedure Stop;
    27     property IsHighResolution : Boolean read fIsHighResolution;
    28     property ElapsedTicks : TLargeInteger read GetElapsedTicks;
    29     property ElapsedMiliseconds : TLargeInteger read GetElapsedMiliseconds;
    30     property Elapsed : string read GetElapsed;
    31     property IsRunning : Boolean read fIsRunning;
     27    property IsHighResolution: Boolean read FIsHighResolution;
     28    property ElapsedTicks: TLargeInteger read GetElapsedTicks;
     29    property ElapsedMiliseconds: TLargeInteger read GetElapsedMiliseconds;
     30    property Elapsed: string read GetElapsed;
     31    property IsRunning: Boolean read FIsRunning;
    3232  end;
     33
    3334
    3435implementation
    3536
    36 constructor TStopWatch.Create(const startOnCreate : boolean = false) ;
     37constructor TStopWatch.Create(const StartOnCreate: Boolean = False);
    3738begin
    38   inherited Create;
     39  FIsRunning := False;
    3940
    40   fIsRunning := False;
    41 
    42   {$IFDEF Windows}
     41  {$IFDEF WINDOWS}
    4342  fIsHighResolution := QueryPerformanceFrequency(fFrequency) ;
    4443  {$ELSE}
    45   fIsHighResolution := False;
     44  FIsHighResolution := False;
    4645  {$ENDIF}
    47   if NOT fIsHighResolution then fFrequency := MSecsPerSec;
     46  if NOT FIsHighResolution then FFrequency := MSecsPerSec;
    4847
    4948  if StartOnCreate then Start;
     
    5251function TStopWatch.GetElapsedTicks: TLargeInteger;
    5352begin
    54   Result := fStopCount - fStartCount;
     53  Result := FStopCount - FStartCount;
    5554end;
    5655
    57 procedure TStopWatch.SetTickStamp(var lInt : TLargeInteger) ;
     56procedure TStopWatch.SetTickStamp(var Value: TLargeInteger);
    5857begin
    59   if fIsHighResolution then
     58  if FIsHighResolution then
    6059    {$IFDEF Windows}
    61     QueryPerformanceCounter(lInt)
     60    QueryPerformanceCounter(Value)
    6261    {$ELSE}
    6362    {$ENDIF}
    6463  else
    65     lInt := MilliSecondOf(Now) ;
     64    Value := MilliSecondOf(Now);
    6665end;
    6766
    6867function TStopWatch.GetElapsed: string;
    6968var
    70   dt: TDateTime;
     69  Elapsed: TDateTime;
    7170begin
    72   dt := ElapsedMiliseconds / MSecsPerSec / SecsPerDay;
    73   result := Format('%d days, %s', [Trunc(dt), FormatDateTime('hh:nn:ss.z', Frac(dt))]) ;
     71  Elapsed := ElapsedMiliseconds / MSecsPerSec / SecsPerDay;
     72  Result := Format('%d days, %s', [Trunc(Elapsed), FormatDateTime('hh:nn:ss.z', Frac(Elapsed))]) ;
    7473end;
    7574
    7675function TStopWatch.GetElapsedMiliseconds: TLargeInteger;
    7776begin
    78   Result := (MSecsPerSec * (fStopCount - fStartCount)) div fFrequency;
     77  Result := (MSecsPerSec * (fStopCount - FStartCount)) div FFrequency;
    7978end;
    8079
    8180procedure TStopWatch.Start;
    8281begin
    83   SetTickStamp(fStartCount);
    84   fIsRunning := True;
     82  SetTickStamp(FStartCount);
     83  FIsRunning := True;
    8584end;
    8685
    8786procedure TStopWatch.Stop;
    8887begin
    89   SetTickStamp(fStopCount);
    90   fIsRunning := False;
     88  SetTickStamp(FStopCount);
     89  FIsRunning := False;
    9190end;
    9291
Note: See TracChangeset for help on using the changeset viewer.