Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

is TTimer without a form possible? (sorry for the cross-posting)

10 views
Skip to first unread message

Sven Pran

unread,
Oct 19, 2007, 8:28:26 AM10/19/07
to
Sorry for the cross-posting, I intended this for
"general" which I think is the best suited group,
but discover that I first posted it to "win32" by
mistake.

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

Marc Rohloff [TeamB]

unread,
Oct 19, 2007, 9:21:59 AM10/19/07
to
On Fri, 19 Oct 2007 14:28:26 +0200, Sven Pran wrote:

> 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

Rob Kennedy

unread,
Oct 19, 2007, 9:42:55 AM10/19/07
to
Marc Rohloff [TeamB] wrote:
> On Fri, 19 Oct 2007 14:28:26 +0200, Sven Pran wrote:
>> If it is possible then how do I set the property
>> MyTimer.OnTimer to point to
>> procedure MyTimerEvent(Sender:TObject); ?
>
> t.OnTImer := MyTImerEvent;

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

Sven Pran

unread,
Oct 19, 2007, 9:50:15 AM10/19/07
to

"Rob Kennedy" <m...@privacy.net> wrote in message
news:4718b45d$1...@newsgroups.borland.com...

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


Dennis Passmore

unread,
Oct 19, 2007, 10:28:42 AM10/19/07
to
If you just want to wait until the time runs out then
just use a simply delay procedure.

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;


Marc Rohloff [TeamB]

unread,
Oct 19, 2007, 11:13:37 AM10/19/07
to
On Fri, 19 Oct 2007 09:21:59 -0400, Marc Rohloff [TeamB] wrote:

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

Sven Pran

unread,
Oct 19, 2007, 12:00:57 PM10/19/07
to

"Marc Rohloff [TeamB]" <ma...@nospam.marcrohloff.com> wrote in message
news:511nt67e...@dlg.marcrohloff.com...

> On Fri, 19 Oct 2007 09:21:59 -0400, Marc Rohloff [TeamB] wrote:
>
>>> 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


0 new messages