Jump to content

Timer

- - - - -

  • Please log in to reply
3 replies to this topic

#1
BramS

BramS

    Newbie

  • Members
  • PipPip
  • 13 posts
Hi,

I want to make a timer in my program, my program has to wait 5 seconds between making the calculation and showing an answer.

Can someone help me please:D?

Grtz

#2
LuthfiHakim

LuthfiHakim

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 765 posts
Hello BramS, Welcome aboard!

You can put delay with sleep between the calculation and showing the answer like this:


  Answer := CalculateAnswer;

  Sleep(5000);

  ShowAnswer(Answer);


But if you use that in a form or in main thread of GUI application, your program will not responding (appears like hung) for 5 seconds. So this solution is great only if you are doing it in separate thread in GUI application or in console application. For GUI application you may want to use TTimer component. Check the System tab in component palette.

Enable the TTimer at the end of calculation and in its OnTimer event show the answer. Do forget to disable the TTimer after you display the answer.

#3
BramS

BramS

    Newbie

  • Members
  • PipPip
  • 13 posts
Thank you LuthfiHakim, this really helped me, my program works fine now :)

#4
LuthfiHakim

LuthfiHakim

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 765 posts
Glad to be of help. Hope I will see you around :c-cool:




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users