Jump to content

Recommended Posts

I need a millisecond counter (NOT a timer) that can operate on Hours/Minutes/Seconds with an upper limit of > 1000 hr. Delphi's TTime and TTimeStamp aren't what I need - does anyone know of anyhing suitable? Without too much effort I could probably put something together using a record helper with a simple Cardinal type, but if something already exists I don't want to reinvent the wheel.

Share this post


Link to post
Posted (edited)
37 minutes ago, Paul H said:

I need a millisecond counter (NOT a timer) that can operate on Hours/Minutes/Seconds with an upper limit of > 1000 hr. Delphi's TTime and TTimeStamp aren't what I need - does anyone know of anyhing suitable? Without too much effort I could probably put something together using a record helper with a simple Cardinal type, but if something already exists I don't want to reinvent the wheel.

You can use from unit System.DIagnostics the TStopWatch "record":

 

Uses System.Diagnostics;

var a:TStopWatch;

begin
	a := TStopWatch.StartNew;
	....
	....
	a.Stop;
	ShowMessage(a.ElapsedMilliseconds.toString);
end;

For better infohttps://docwiki.embarcadero.com/Libraries/Athens/en/System.Diagnostics.TStopwatch

P.S.: you have also the "Elapsed" property that maintain the features you required (but you can simple calculate them from "milliseconds".

 

Edited by DelphiUdIT

Share this post


Link to post
1 hour ago, Paul H said:

I need a millisecond counter (NOT a timer) that can operate on Hours/Minutes/Seconds with an upper limit of > 1000 hr.

Use GetTickCount64 in the unit Winapi.Windows. It returns the number of milliSec elapsed since the computer has been powered on.

Share this post


Link to post

Thanks for both comments, but I don't need a timer, so TStopwatch or the system timer are't suitable either. I am building a time based numerical integrator, so real time is not important, I will be setting the integrator "time" manualy as needed. The Time Counter merely keeps track of where we are in the integration and provides the integration time step.

Share this post


Link to post

Thanks David - I was hoping to find something with H-M-S support including setting / getting in decimals the way you can with TTime. It is probably no more than a couple of hours work to do something basic with a record helper, I just didn't want to duplicate something that already exists.

Share this post


Link to post
23 minutes ago, Paul H said:

Thanks David - I was hoping to find something with H-M-S support including setting / getting in decimals the way you can with TTime. It is probably no more than a couple of hours work to do something basic with a record helper, I just didn't want to duplicate something that already exists.

I mean you didn't say any of this in your original post. Clearly you knew what your requirements were, but we can't read your kind! 

Edited by David Heffernan

Share this post


Link to post

I did say originally I wanted a counter with H-M-S support, which (to me at least) implies decimal input/output. Sorry if that wasn't clear to you.

Share this post


Link to post
8 minutes ago, Paul H said:

I did say originally I wanted a counter with H-M-S support, which (to me at least) implies decimal input/output. Sorry if that wasn't clear to you.

Yes, my fault. Sorry.

Share this post


Link to post
43 minutes ago, Paul H said:

Thanks David - I was hoping to find something with H-M-S support including setting / getting in decimals the way you can with TTime. It is probably no more than a couple of hours work to do something basic with a record helper, I just didn't want to duplicate something that already exists.

Like I wrote, there is also Elapsed, that is based on TTimeSpawn: https://docwiki.embarcadero.com/Libraries/Sydney/en/System.TimeSpan.TTimeSpan

 

You can use that advanced record ...

Edited by DelphiUdIT

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×