Timer lazarus / 21-General ---------------------------------------------------------------------- michoux · 2023-06-12 05:35 Hello, I am building a graphic controller for sport timing events. I receive a start pulse from timing software when athlete starts, at this point I would need to start a  running time for athlete, to show it on TV graphic. Timing software can not give me running time of athlete so I need to simulate it. I would have around 8 athletes on course at the same time. Any ideas how to simulate this running time. When athlete arrives to finish I will receive his finish time again from timing software. ---------------------------------------------------------------------- domasz · 2023-06-12 08:49 8 x TTimer ---------------------------------------------------------------------- michoux · 2023-06-12 09:09 Can I get time from ttimer? ---------------------------------------------------------------------- rvk · 2023-06-12 09:15 You can use an implementation of TStopWatch. https://forum.lazarus.freepascal.org/index.php/topic,44428.msg312342.h tml#msg312342 Or use EpikTimer. https://wiki.freepascal.org/EpikTimer ---------------------------------------------------------------------- domasz · 2023-06-12 09:16 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i public  GlobalTime, Elapsed: Int64; ...  GlobalTime := getTickCount;Timer1.Enabled := True; Timer1.OnTimer: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Elapsed := getTickCount - GlobalTime; //in milisecond ---------------------------------------------------------------------- rvk · 2023-06-12 09:20 Quote from: domasz on June 12, 2023, 11:16:36 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i public  GlobalTime, Elapsed: Int64; ...GlobalTime := getTickCount;Timer1.Enabled := True; Timer1.OnTimer: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Elapsed := getTickCount - GlobalTime; //in milisecond And what interval would you use in that case?? It should be very small to accurately have milliseconds in Elapsed. TStopWatch or EpikTimer are better options. ---------------------------------------------------------------------- domasz · 2023-06-12 09:28 Depends how precisely you want to display the results. I think the interval can be 500 or 1000, display with accuracy to seconds and after disabling the timer show the final result with greater precision. ---------------------------------------------------------------------- rvk · 2023-06-12 09:32 Quote from: domasz on June 12, 2023, 11:28:32 amDepends how precisely you want to display the results. I think the interval can be 500 or 1000, display with accuracy to seconds and after disabling the timer show the final result with greater precision. Yes, but when you stop the timer you still need to call the last OnTimer to get the final accurate result. And if you are going to do that you can just as wel NOT use TTimer and define 8 Elapsed{1..8} variables. At start you set the getTickCount64 in there and when you want the time you do getTickCount64 - Elapsed{1..8}. A TTimer doesn't add that much in that case. If you want individual TObjects with the elapsed time.., accurately to milliseconds, without having to call OnTimer manually, EpikTimer and TStopWatch are easier. ---------------------------------------------------------------------- domasz · 2023-06-12 09:38 Simple example with TTimer. Perhaps TStopWatch or EpikTimer would be better. I think it can be easily done with TTimer and TTimer is available in every Lazarus and Delphi without installing anything. ---------------------------------------------------------------------- michoux · 2023-06-12 23:44 Thank you for all the answers. I will not use the this timer for accurate time, it is just to display running time of competitor, can be even just in seconds ... ok perhaps 10s of seconds not more ... The start and finish time I get from GPS synchronized timing device ... Start is an event which I can receive from a timing device, with the bib number of competitor, at this time I need to start a timer for this competitor and I need to show it when required ... When this competitor finishes I can destroy this time .... ---------------------------------------------------------------------- michoux · 2023-06-26 08:07 Hi again. One question on epik timer, I will not open a new post for this. Here is my situation. I have a start time of on competitor in seconds. For example: 33286 this is equal to day time of 09:14:46 Now I want to get the current time and let say that time now is 09:15:46 so one minute already passed. I want to give this already elapsed time to epik timer and start it from there, so elapsed time in epik timer should be already 1 minute. Then I would start another normal timer to display this elapsed time Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Timer1Timer(Sender: TObject);begin     label1.Caption:= Epiktimer1.ElapsedStr;end;  Any idea how to do this? ---------------------------------------------------------------------- KodeZwerg · 2023-06-26 08:38 I'd suggest to switch over to TStopWatch. ---------------------------------------------------------------------- rvk · 2023-06-26 09:22 Quote from: michoux on June 26, 2023, 10:07:11 amNow I want to get the current time and let say that time now is 09:15:46 so one minute already passed. I want to give this already elapsed time to epik timer and start it from there, so elapsed time in epik timer should be already 1 minute.So you want to start a timer with a start time in the past ???? You could call TEpikTimer.Start(var T: TimerData); with a TimerData parameter which contains a different starttime. If Start is called and TimerData.running := true then it will leave StartTime alone. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TEpikTimer.Start(var T: TimerData);begin  if not T.running then    With FSelectedTimebase^ do    begin      T.StartTime:=Ticks()-TicksOverhead;      T.TimebaseUsed:=FSelectedTimebase;      T.Running:=True    endend; ---------------------------------------------------------------------- michoux · 2023-06-26 10:16 THanks, In this case what would be "TimerData"? ---------------------------------------------------------------------- rvk · 2023-06-26 10:37 Quote from: michoux on June 26, 2023, 12:16:38 pmIn this case what would be "TimerData"? It's a record defined in EpikTimer. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TimerData = record    Running:Boolean; // Timer is currently running  TimebaseUsed:TimeBaseSelector; // keeps timer aligned with the source that started it.    StartTime:TickType; // Ticks sample when timer was started    TotalTicks:TickType; // Total ticks... for snapshotting and pausing  end; ---------------------------------------------------------------------- michoux · 2023-06-26 17:59 Hi I found an easy solution just wit ttimer Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   procedure TForm1.Timer1Timer(Sender: TObject);     var H,M,S,S2,MS,s3 : word;      runningtime:TDateTime;    begin       DecodeTime(69214902 /1000/60/60/024, H, M, S, MS);       runningtime:=Now- EncodeTime(H,M,S,MS);       label1.Caption:=FormatDateTime('hh.mm.ss.zzz',runningtime);    end; ---------------------------------------------------------------------- Nicole · 2023-06-27 08:32 I am happy with the tvPlanit-Timer. tvPlanit was a commercial project which was given up and made open source. It contains a really nice calender and a function with watch timer alert See the demo there.