I need a Timer in a 'no form' Delphi unit (there's still a main unit with a form), so I do this:
unit ...
interface
type
TMyTimer = Class(TTimer)
public
procedure OnMyTimer(Sender: TObject);
end;
var
MyTimer: TMyTimer;
implementation
procedure TMyTimer.OnMyTimer(Sender: TObject);
begin
...
end;
initialization
MyTimer := TMyTimer.Create(nil);
with MyTimer do
begin
Interval := 1000;
Enabled := True;
OnTimer := OnMyTimer;
end;
finalization
FreeAndNil(MyTimer);
The problem is that the OnMyTimer procedure is never run. I'll truly appreciate any ideas as to why :-)