I could use a TTimer component in a unit
which do not include any form (so I have
nowhere to "drop" TTimer on the IDE) and
wonder if that is possible at all.
If it is possible then how do I set the property
MyTimer.OnTimer to point to
procedure MyTimerEvent(Sender:TObject); ?
regards Sven
> I could use a TTimer component in a unit
> which do not include any form (so I have
> nowhere to "drop" TTimer on the IDE) and
> wonder if that is possible at all.
Just create it in code:
t := TTImer.Create(nil);
Don't forget to free it when you are done.
> If it is possible then how do I set the property
> MyTimer.OnTimer to point to
> procedure MyTimerEvent(Sender:TObject); ?
t.OnTImer := MyTImerEvent;
--
Marc Rohloff [TeamB]
marc -at- marc rohloff -dot- com
But remember that the event handler must be a member of a class. It
can't be a standalone function.
It can be a class method, though:
type
TTimerHandler = class
class procedure DoTimer(Sender: TObject);
end;
t.OnTimer := TTimerHandle.DoTimer;
Now you don't need to instantiate TTimerHandler.
--
Rob
Thanks for both answers!
You confirm the ideas I eventually reached while walking today.
On coming home I was about ready to try it out.
regards Sven
Its totally standalone and only needs Messages to compile.
procedure Delay(millseconds: dword);
var
fTimerId: UINT;
TimerMsg: TMsg;
begin
fTimerId := SetTimer(0, 0, millseconds, nil);
while (fTimerId > 0) and GetMessage(TimerMsg, 0, 0, 0) do
begin
TranslateMessage(TimerMsg);
DispatchMessage(TimerMsg);
with TimerMsg do
if (message = UINT(WM_QUIT)) or
((message = UINT(WM_TIMER)) and (UINT(wparam) = fTimerId)) then
break;
end;
if (fTimerId > 0) then
KillTimer(0, fTimerId);
end;
>> I could use a TTimer component in a unit
>> which do not include any form (so I have
>> nowhere to "drop" TTimer on the IDE) and
>> wonder if that is possible at all.
I should point out that using a TTimer requires you to have a message
loop running somewhere for it to work.
Good point but no problem
Thanks for the comment anyway
regards Sven