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
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?