Forum > LCL

[SOLVED] Create TTimer

(1/1)

Pe3s:
Hello forum users, what is the correct method of creating a TTimer in code? . Do I need to delete it in FormDestroy?

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.CreateTimer;begin  if not Assigned(Timer) then  begin    Timer:= TTimer.Create(Self);    with Timer dobegin  Interval:= 1000;  OnTimer:= @TimerUpdate;  Enabled:= False;  end;  end;end; or

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var  Timer1: TTimer;begin  Timer1 := TTimer.Create(Self);  Timer1.Interval := 1000;  Timer1.OnTimer := Timer1Timer;  Timer1.Enabled := True; end; 

alpine:
I think you misspelled it on the line 5: VideoTimer instead of Timer.
And as long as it has an owner, you don't need to free it.

Pe3s:
Thank you :)

ASerge:

--- Quote from: Pe3s on May 16, 2023, 05:22:35 pm ---Hello forum users, what is the correct method of creating a TTimer in code? . Do I need to delete it in FormDestroy?

--- End quote ---
If you call the CreateTimer method more than once, then the second method is preferable. In this case, you can explicitly remove the timer and set the Timer field to nil (FreeAndNil).
If the owner is specified when creating the component, then as a rule it is responsible for deleting.

Pe3s:
Thank you :)

Navigation

[0] Message Index

Go to full version