Re: NTLK Programming questions...

From: Paul Guyot (pguyot@pnm-consulting.com)
Date: Mon Aug 21 2000 - 16:42:52 CDT


Hi Jim,

> I'm working on a program that uses a timer. I've got a function in a
>frame called Timer(). In it, I make a call to AddDelayedCall(Timer, nil,
>1000), but the program errors out at that point. According to the
>documentation for AddDelayedCall, the first parameter is supposed to be the
>function object that gets called after the delay, but I don't seem to be
>passing in the function correctly. The error I get is -48807 (undefined
>variable). What am I doing wrong here?

It is very probably that the function isn't retrieved properly.

Indeed, when you write AddDelayedCall( Timer, nil, 1000) it is
translated into bytecode with one which says Push 'Timer and the
following is FindVariable. (well, it's a long time since I've been in
bytecode, I'm rather in ARM instructions those days, hence the names
may be incorrect).

The exception is thrown when FindVariable fails.

There are only three places where the system looks for a variable:

This code works:

{
invokeTimer: func ()
begin
   ....
   AddDelayedTimer(Timer, nil, 1000);
   ....
end,
Timer: func ()
begin
   ....
end,
.....
} in myObject
and the invokeTimer is called by myObject:invokeTimer();
(not by call myObject.invokeTimer with () which calls it
independently from myObject).

This way, when the function invokeTimer is called, the reciever is
set to myObject, and looking for Timer succeeds. In fact, the
variable is looked for in both _proto & _parent chain (_proto first,
then _parent).

Here is the second valid example: a local variable.
begin
   local Timer := func () begin .... end;
   AddDelayedTimer(Timer, nil, 1000);
end;

The third and last case this works is a global variable. (I don't
develop it because you probably don't need it and you'll better not
use it)

Anything else fails (sure, there are mystic methods if you really
wanna know, but unless you touch to the ARM layer, all working cases
can be reduced to those three samples). And I guess that you are in
an anything else case.

Hope I've been clear enough.

Regards,

Paul

-- 
P&M Consulting Newton Program
http://www.pnm-consulting.com/newton/
***************************************
NewtonTalk brought to you by:

EVOTE.COM -- the ESPN of politics on the Internet! All the players, all the news, and the hottest analysis and features (plus 'toons!) anywhere.... visit http://www.evote.com today!

*************************************** Need Subscribe/Unsubscribe info?

Visit the NewtonTalk section at http://www.planetnewton.com



This archive was generated by hypermail 2b29 : Fri Sep 01 2000 - 00:00:14 CDT