<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <div class="moz-cite-prefix">El 18/10/2020 a las 19:18, Lars via
      lazarus escribió:<br>
    </div>
    <blockquote type="cite"
      cite="mid:5f801a95aade93b0bce4cba80e74ab9b@z505.com">When building
      a simple TTimer demo I cannot seem to get it working
      <br>
      <br>
      Any idea what the problem could be if you paste this code into
      your form with a memo?
      <br>
      <br>
      var
      <br>
        TimeSpent: integer;
      <br>
      <br>
      procedure TForm2.Button1Click(Sender: TObject);
      <br>
      var
      <br>
        i, answer: integer;
      <br>
      begin
      <br>
        Timer1.enabled := false;
      <br>
        TimeSpent := 0;
      <br>
        Timer1.Enabled := true;
      <br>
        Timer1.interval := 1;
      <br>
        for i := 0 to 999999999 do
      <br>
        begin
      <br>
          answer := i * answer;
      <br>
        end;
      <br>
      <br>
        memo1.lines.add('time spent: ' + inttostr(timespent));
      <br>
      <br>
      end;
      <br>
      <br>
      procedure TForm2.Timer1Timer(Sender: TObject);
      <br>
      begin
      <br>
        inc(TimeSpent);
      <br>
      end;
      <br>
      <br>
      It says
      <br>
      time spent: 0
      <br>
      Whereas the time should be a lot.
      <br>
      <br>
      Regards,
      <br>
      Lars
      <br>
    </blockquote>
    <br>
    I don't know what are you trying to do, but if you are trying to
    find out how long it takes certain process, you should try other
    approach. Timer is low precision and it is only fired by events, so
    you must process event's queue.<br>
    <br>
    A first and bad approach:<br>
    <pre>for i := 0 to 999999999 do
begin
   answer := i * answer;
   application.processmessages; //<-- process event queue
end;
</pre>
    But this is very not a very efficient way. The best is to get the
    start time, get the end time and subtract.<br>
    <pre>var
  StartTime,EndTime:TDataTime;
  i, answer: integer;
begin
 StartTime:=now;
 for i := 0 to 999999999 do
 begin
    answer := i * answer;
 end;
 EndTime:=now;
 memo1.lines.add('time spent: ' + TimeToStr(EndTime-StarTime) );
end;</pre>
    But TDateTime is not accurate at all if you are measuring short
    periods (milliseconds). <br>
    <br>
    EpikTimer is a component with much better precision.<br>
    <br>
    <a class="moz-txt-link-freetext" href="https://wiki.lazarus.freepascal.org/EpikTimer">https://wiki.lazarus.freepascal.org/EpikTimer</a><br>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
Saludos

Santiago A.</pre>
  </body>
</html>