A High Resolution for Most Win95 Systems

{
   File Name: HRTimer.PAS V1.00
   Created: Apr 17 1997, 06:40 on the ThinkPAd by John Mertus
   Revision #6: Oct 12 1997, 10:56 on the Gateway by John Mertus

   This is a wrapper around the High Resolution Timer in
   Win95/WinNT

   Var
     HRT : THRTimer

   HRT := THRTimer.Create;
   HRT.StartTimer;  Resets the timer to zero
   HRT.ReadTimer;   Returns the elapsed time in milliseconds
                     since the time start

   HRT.Free;

   Edit history
        Version  1.00  Initial release

Quote
}

{------------------Unit HRTimer---------------------John Mertus April 97---}

                    Unit HRTimer;

{--------------------Interface-------------------------------}

                    interface

Uses Windows;

Type
   THRTimer = Class(TObject)
     Constructor Create;
     Function StartTimer : Boolean;
     Function ReadTimer : Double;

   private
     StartTime : Double;
     ClockRate : Double;

   public
     Exists    : Boolean;

   End;

{------------------------Implementation---------------------------------}

                    implementation

{------------------Create-------------------------John Mertus----Mar 97-}

     Constructor THRTimer.Create;

{ This reads the windows HR time and stores it for later use.             }
{                                                                         }
{*************************************************************************}
Var
  QW : TLargeInteger;

BEGIN
   Inherited Create;
   Exists := QueryPerformanceFrequency(QW);
   ClockRate := QW.QuadPart;
END;

{------------------StartTimer---------------------John Mertus----Mar 97-}

   Function THRTimer.StartTimer : Boolean;

{ This reads the windows HR time and stores it for later use.             }
{                                                                         }
{*************************************************************************}
Var
   QW : TLargeInteger;

BEGIN
   Result := QueryPerformanceCounter(QW);
   StartTime := QW.QuadPart;
END;

{-------------------ReadTimer---------------------John Mertus----Mar 97---}

   Function THRTimer.ReadTimer : Double;

{ This reads the windows HR time and stores it for later use.             }
{                                                                         }
{*************************************************************************}
Var
   ET : TLargeInteger;

BEGIN
   QueryPerformanceCounter(ET);
   Result := 1000.0*(ET.QuadPart - StartTime)/ClockRate;
END;

end.