[Solved] How to use TTimer without a form lazarus / 21-General ---------------------------------------------------------------------- Wilko500 · 2025-06-10 18:40 MacOs Laz 4.1 FPC 3.2.2 My program under development has six timers (TTimer) all set up on the main form. Currently they are coded so that each has both a fire and tick procedure.  They work just fine but I would like to put all these timers into a single unit eg TimerUnit.  I have been unable to get this to work so I went back to a simple example I found on the web, helped by AI lol, but it does not compile 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 unit TimerUnit; interface uses  SysUtils, Classes, extCrtls; type  TMyTimer = class(TObject)  private    FTimer: TTimer;    FOnTimer: TTimerEvent;      // <=Compile error identifier not found TTimerEvent    procedure OnTimerEvent(Sender: TObject);  public    constructor Create;    destructor Destroy; override;    procedure Start(Interval: Integer; OnTimer: TTimerEvent);    procedure Stop;  end; implementation { TMyTimer } constructor TMyTimer.Create;begin  FTimer := TTimer.Create(nil);  FTimer.Enabled := False;  FTimer.OnTimer := OnTimerEvent;end; destructor TMyTimer.Destroy;begin  FTimer.Free;  inherited;end; procedure TMyTimer.Start(Interval: Integer; OnTimer: TTimerEvent);begin  FTimer.Interval := Interval;  FOnTimer := OnTimer;  FTimer.Enabled := True;end; procedure TMyTimer.Stop;begin  FTimer.Enabled := False;end; procedure TMyTimer.OnTimerEvent(Sender: TObject);begin  FOnTimer(Sender);end; end.Compiler errors on line 12 with identifier not found TTimerEvent Getting this working was supposed to be a starting point for migrating my existing code. Maybe one of you has a simple working example of a TTimer in a unit rather than a form? ---------------------------------------------------------------------- Phoenix · 2025-06-10 19:36 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 unit TimerUnit; {$mode objfpc}{$H+} interface uses  SysUtils, Classes, ExtCtrls; type  TMyTimer = class(TObject)  private    FTimer: TTimer;    FOnTimer: TNotifyEvent;    procedure OnTimerEvent(Sender: TObject);  public    constructor Create;    destructor Destroy; override;    procedure Start(Interval: Integer; OnTimer: TNotifyEvent);    procedure Stop;  end; implementation { TMyTimer } constructor TMyTimer.Create;begin  FTimer := TTimer.Create(nil);  FTimer.Enabled := False;  FTimer.OnTimer := @OnTimerEvent;end; destructor TMyTimer.Destroy;begin  FTimer.Free;  inherited;end; procedure TMyTimer.Start(Interval: Integer; OnTimer: TNotifyEvent);begin  FTimer.Interval := Interval;  FOnTimer := OnTimer;  FTimer.Enabled := True;end; procedure TMyTimer.Stop;begin  FTimer.Enabled := False;end; procedure TMyTimer.OnTimerEvent(Sender: TObject);begin  FOnTimer(Sender);end; end. ---------------------------------------------------------------------- Wilko500 · 2025-06-10 20:36 @Phoenix, thank you.  Very helpful.  I see that AI inspired help has a little way to go but to be fair it was close.  Shame I wasn't sharp enough to spot the errors.  For now I'll mark this post as solved and then I'll see if I can get my more complicated timer procedure to work. Update:  Took a few attempts but I now have the basic timer working to update main form time field with the timer code in the TimerUnit.  When I have more time I'll try with the more complicated timer code.  This should simplify my code because I think I can create a separate class instance for each of my timers and then have a separate Tick and Fire for each.  At the moment the entire timer code is duplicated for each timer.