| View previous topic :: View next topic |
| Author |
Message |
Larry Alda Guest
|
Posted: Mon Oct 27, 2003 6:59 pm Post subject: TTimer events overlapping! |
|
|
I have 2 objects of the same class on a form.
Each object contains its own TTimer component (created runtime).
The OnTimer event of object 1 is overlapped by the OnTimer of
object 2. Actually, whatever object is created last gets the
active OnTimer event. I tried giving the timers unique names
and/or different owners, still the problem persists. If I give
each timer a unique OnTimer event to use, then it works, but
that is very strange. I shouldn't have to do that. Any ideas
from the pros here? Thanks
|
|
| Back to top |
|
 |
Mike Williams (TeamB) Guest
|
Posted: Mon Oct 27, 2003 7:12 pm Post subject: Re: TTimer events overlapping! |
|
|
On 27 Oct 2003, "Larry Alda" <L35alda (AT) hotmail (DOT) com> wrote:
| Quote: | I have 2 objects of the same class on a form.
Each object contains its own TTimer component (created runtime).
The OnTimer event of object 1 is overlapped by the OnTimer of
object 2. Actually, whatever object is created last gets the
active OnTimer event.
|
Please post some code. Specifically, where are you setting the timer's
OnTimer event at runtime?
--
-Mike (TeamB)
|
|
| Back to top |
|
 |
Larry Alda Guest
|
Posted: Mon Oct 27, 2003 7:21 pm Post subject: Re: TTimer events overlapping! |
|
|
"Mike Williams (TeamB)" <mikew (AT) remove (DOT) aps-soft.com> wrote:
| Quote: | On 27 Oct 2003, "Larry Alda" <L35alda (AT) hotmail (DOT) com> wrote:
Please post some code. Specifically, where are you setting the timer's
OnTimer event at runtime?
|
Ok.. it looks like this:
tmrUpdate.OnTimer := self.tmrUpdateTimer;//works the same with or without "self"
It was in the constructor. I moved it to a later procedure
with no change in this behavior. Like I said, if I assign an
object specific event then it works.
|
|
| Back to top |
|
 |
Mike Williams (TeamB) Guest
|
Posted: Mon Oct 27, 2003 7:34 pm Post subject: Re: TTimer events overlapping! |
|
|
On 27 Oct 2003, "Larry Alda" <L35alda (AT) hotmail (DOT) com> wrote:
| Quote: | Ok.. it looks like this:
tmrUpdate.OnTimer := self.tmrUpdateTimer;//works the same with or
without "self"
It was in the constructor. I moved it to a later procedure
with no change in this behavior. Like I said, if I assign an
object specific event then it works.
|
Ok, so you're just redirecting the event handler to the parent component
handler. Where is that getting set? Somewhere you're pointing to the
same event handler (if I understand your problem correctly).
--
-Mike (TeamB)
|
|
| Back to top |
|
 |
Larry Alda Guest
|
Posted: Mon Oct 27, 2003 7:47 pm Post subject: Re: TTimer events overlapping! |
|
|
"Mike Williams (TeamB)" <mikew (AT) remove (DOT) aps-soft.com> wrote:
| Quote: |
Ok, so you're just redirecting the event handler to the parent component
handler. Where is that getting set? Somewhere you're pointing to the
same event handler (if I understand your problem correctly).
|
"self" is the specific class object. There are 2 separate
class objects... which doesn't makes sense why their wires are
getting crossed. I have hundreds of other sub-classes within
each of these objects, and its only the TTimer events that are
getting confused.
|
|
| Back to top |
|
 |
Mike Williams (TeamB) Guest
|
Posted: Mon Oct 27, 2003 8:23 pm Post subject: Re: TTimer events overlapping! |
|
|
On 27 Oct 2003, "Larry Alda" <L35alda (AT) hotmail (DOT) com> wrote:
| Quote: | I have hundreds of other sub-classes within
each of these objects, and its only the TTimer events that are
getting confused.
|
I agree. This may be one of those cases where you're staring right at
the problem and just don't see it.
One option would be to have all timers share the same event and use the
sender paramter to differentiate: <g>
procedure TForm1.Timer2Timer(Sender: TObject);
begin
if Sender = Timer1 then begin
Memo1.Lines.Add('Timer1');
end else begin
Memo1.Lines.Add('Timer2');
end;
end;
--
-Mike (TeamB)
|
|
| Back to top |
|
 |
Larry Alda Guest
|
Posted: Mon Oct 27, 2003 10:27 pm Post subject: Re: TTimer events overlapping! |
|
|
"Mike Williams (TeamB)" <mikew (AT) remove (DOT) aps-soft.com> wrote:
| Quote: | I agree. This may be one of those cases where you're staring right at
the problem and just don't see it.
One option would be to have all timers share the same event and use the
sender paramter to differentiate:
procedure TForm1.Timer2Timer(Sender: TObject);
begin
if Sender = Timer1 then begin
Memo1.Lines.Add('Timer1');
end else begin
Memo1.Lines.Add('Timer2');
end;
end;
|
I moved the TTimer declaration from the unit section to the
private section and now it works as expected. Does that even
make sense??
|
|
| Back to top |
|
 |
Mike Williams (TeamB) Guest
|
Posted: Tue Oct 28, 2003 12:51 am Post subject: Re: TTimer events overlapping! |
|
|
On 27 Oct 2003, "Larry Alda" <L35alda (AT) hotmail (DOT) com> wrote:
| Quote: | I moved the TTimer declaration from the unit section to the
private section and now it works as expected. Does that even
make sense??
|
Perhaps there was a scoping conflict where two identifiers had the same
name in different places. By making one of them private the other was
found by the compiler instead.
However, that's just speculation. I'm glad you got it working.
--
-Mike
|
|
| Back to top |
|
 |
Larry Alda Guest
|
Posted: Tue Oct 28, 2003 1:04 pm Post subject: Re: TTimer events overlapping! |
|
|
"Mike Williams (TeamB)" <mikew (AT) remove (DOT) aps-soft.com> wrote:
| Quote: | Perhaps there was a scoping conflict where two identifiers had the same
name in different places. By making one of them private the other was
found by the compiler instead.
However, that's just speculation. I'm glad you got it working.
|
Thanks for your help, Mike. Sometimes it helps prompt an idea
just to talk it over with someone.
|
|
| Back to top |
|
 |
|