[Lazarus] TTimer simple issue
Luca Olivetti
luca at wetron.es
Mon Oct 26 11:27:40 CET 2020
El 18/10/20 a les 19:18, Lars via lazarus ha escrit:
> When building a simple TTimer demo I cannot seem to get it working
>
> Any idea what the problem could be if you paste this code into your form
> with a memo?
>
> var
> TimeSpent: integer;
>
> procedure TForm2.Button1Click(Sender: TObject);
> var
> i, answer: integer;
> begin
> Timer1.enabled := false;
> TimeSpent := 0;
> Timer1.Enabled := true;
> Timer1.interval := 1;
> for i := 0 to 999999999 do
> begin
> answer := i * answer;
> end;
>
> memo1.lines.add('time spent: ' + inttostr(timespent));
>
> end;
>
> procedure TForm2.Timer1Timer(Sender: TObject);
> begin
> inc(TimeSpent);
> end;
>
> It says
> time spent: 0
> Whereas the time should be a lot.
No, since your loop is busy waiting the Timer1Timer method is never
fired. Events are only processed in the main gui loop. You could add an
"Application.Processmessages" inside your loop but you must know what
you are doing (e.g. you could click again button1 and that's not desirable).
Bye
--
Luca Olivetti
Wetron Automation Technology http://www.wetron.es/
Tel. +34 93 5883004 (Ext.3010) Fax +34 93 5883007
More information about the lazarus
mailing list