Changeset 571 for Common/StopWatch.pas


Ignore:
Timestamp:
Jun 14, 2024, 9:37:37 PM (5 months ago)
Author:
chronos
Message:
  • Modified: Code cleanup.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Common/StopWatch.pas

    r558 r571  
    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;
    3333
     
    3535implementation
    3636
    37 constructor TStopWatch.Create(const startOnCreate : boolean = false) ;
     37constructor TStopWatch.Create(const StartOnCreate: Boolean = False);
    3838begin
    39   inherited Create;
    40 
    41   fIsRunning := False;
     39  FIsRunning := False;
    4240
    4341  {$IFDEF WINDOWS}
    4442  fIsHighResolution := QueryPerformanceFrequency(fFrequency) ;
    4543  {$ELSE}
    46   fIsHighResolution := False;
     44  FIsHighResolution := False;
    4745  {$ENDIF}
    48   if NOT fIsHighResolution then fFrequency := MSecsPerSec;
     46  if NOT FIsHighResolution then FFrequency := MSecsPerSec;
    4947
    5048  if StartOnCreate then Start;
     
    5351function TStopWatch.GetElapsedTicks: TLargeInteger;
    5452begin
    55   Result := fStopCount - fStartCount;
     53  Result := FStopCount - FStartCount;
    5654end;
    5755
    58 procedure TStopWatch.SetTickStamp(var lInt : TLargeInteger) ;
     56procedure TStopWatch.SetTickStamp(var Value: TLargeInteger);
    5957begin
    60   if fIsHighResolution then
     58  if FIsHighResolution then
    6159    {$IFDEF Windows}
    62     QueryPerformanceCounter(lInt)
     60    QueryPerformanceCounter(Value)
    6361    {$ELSE}
    6462    {$ENDIF}
    6563  else
    66     lInt := MilliSecondOf(Now) ;
     64    Value := MilliSecondOf(Now);
    6765end;
    6866
    6967function TStopWatch.GetElapsed: string;
    7068var
    71   dt: TDateTime;
     69  Elapsed: TDateTime;
    7270begin
    73   dt := ElapsedMiliseconds / MSecsPerSec / SecsPerDay;
    74   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))]) ;
    7573end;
    7674
    7775function TStopWatch.GetElapsedMiliseconds: TLargeInteger;
    7876begin
    79   Result := (MSecsPerSec * (fStopCount - fStartCount)) div fFrequency;
     77  Result := (MSecsPerSec * (fStopCount - FStartCount)) div FFrequency;
    8078end;
    8179
    8280procedure TStopWatch.Start;
    8381begin
    84   SetTickStamp(fStartCount);
    85   fIsRunning := True;
     82  SetTickStamp(FStartCount);
     83  FIsRunning := True;
    8684end;
    8785
    8886procedure TStopWatch.Stop;
    8987begin
    90   SetTickStamp(fStopCount);
    91   fIsRunning := False;
     88  SetTickStamp(FStopCount);
     89  FIsRunning := False;
    9290end;
    9391
Note: See TracChangeset for help on using the changeset viewer.