• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

Timer/Counter thread

I'm trying to create a counter program that counts the time between the moment you press a start and a stop button (and updates it every second in a TLabel.Caption). Thus far i created a threaded label that updates the caption to the current time every second. I can't figure out how to put in the time difference (how do i send the starting time as a parameter). Does anybody have an idea how to solve this (or better: do you have an example program?)
  • 3
  • 2
  • 2
1 Solution
Yo scheiko,


// ----------------- GetSystemTime -------------------------------

  st : TSystemTime;
  GetSystemTime( st );
  // or GetLocalTime( st );

  // now you can use the st structure to get time info.

So. Call this in the beginning and you got your beginning time. Then do all the stuff you want to do with it. By the way you can also get the time with the function Now.

regards, Zif.
scheiko, maybe an enhanced threaded timer will do the job, uh?

freeware, but I can't remember where I found it, so post your email

My email: bosism@netvision.net.il

Good luck!
scheikoAuthor Commented:
Thanks guys, but...

The calculation of the time difference is not so much the problem. The real trouble is continuously updating the time difference. My application registrates the startingtime at the moment a button is pressed. The thread reads the current time (Now) and displays it (every second) in a TLabel.Caption. How do i pass the starting time to the (unit with the TLabel.Caption) timer. I'll place the source on ftp://scheiko.chem.ruu.nl user anonymous so you can see what i mean. It'll be there until tomorrow 12:00 pm GMT.

Thanks again!
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Sorry, but seeing your code I still don't understand what you just need?

To pass a variable to a unit : there are several ways, one is making in the public declaration the following :

 StartTimeValue : TDateTime read fStartTimeValue write fStartTimeValue

 in the private section write : fStartTimeValue : TDateTime

Now when you want to read this value into a variable do this :

 Inside the unit : TimerStartedAt := fStartTimer
 Outside the unit : TimerStartedAt := Unit1.StartTimeValue

Now when you want to write a value to this variable do this :
 Inside the unit :  fStartTimer := Time
 OutSide the unit : Unit1.StartTimeValue := Time

If this isn't what you want please explain in another way.

Met vriendelijke groeten Zif.

scheikoAuthor Commented:
Dear Zifnab,

Thanks alot, i think you gave me the perfect hunch.

Hi scheiko,

If your answer is answered lets remove this question from the list and grade it.
If you still need some advice, just give a comment.

Regards, Zif.
scheiko, if you still have problems then the timer I have is just what you need.

Post your email...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now