Wie unterbreche ich in Lazarus einen Timer?

Hallo,

Ich habe in Lazarus einen Timer, der seine Aufgaben macht, dabei liegt der Intervall auf 18,6 Sekunden (Ja, der brauch so lange um alle Aufgaben abzuarbeiten).

Ich habe auch eine Tastenabfrage programmiert, damit der Timer deaktiviert wird (Timer1.Enabled:= False;).

Das Problem ist, dass der Timer auch direkt abbrechen soll und seine Aufgaben nicht bis zum Ende des Intervalls machen soll soll.

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
1 Answer
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
iQa1x
1 year ago

Not so easy. A timer is not a separate thread, but runs in the MainThread of the application. While the timer function is running, no other thing happens if you don’t care about it.

In the function that the timer performs, you can insert a break-off treatment at suitable locations, e.g.

Application.ProcessMessages;
if (not Timer1.enabled) then begin
   // Aufräumen
   exit;
end;

The Application.ProcessMessages ensures that other events, such as a click on a break-off button, are processed at all. If the timer deactivates the timer, the code then ensures the termination of the timer function. But you have to put this in yourself.

If you really want to do something parallel, look at TThread…