Variable Scoping
Mark Schonewille
m.schonewille at economy-x-talk.com
Mon Oct 9 13:12:48 EDT 2006
Robert,
If you need a variable to be available to all handlers in an object
(button, field, card, stack, group) you can do the following:
local lVar
on handler1
put x into lVar
handler2
and handler1
on handler2
put lVar
-- message box contains x
end handler 2
but if you need the variable only in handler1 and handler2 and not in
any other handler of the script of that particular object, you can do
on handler1
put x into myVar
handler2 myVar
end handler1
on handler2 theVar
put theVar
-- msg box contains x
end handler2
If you want a variable to be available to all scripts in the IDE or
standalone, replace
local lVar
with
global gVar
and use the following:
global gVar
on handler1
put x into gVar
handler2
and handler1
on handler2
put gVar
-- message box contains x
end handler 2
Hth,
Mark
--
Economy-x-Talk
Consultancy and Software Engineering
http://economy-x-talk.com
http://www.salery.biz
Get your store on-line within minutes with Salery Web Store software.
Download at http://www.salery.biz
Op 7-okt-2006, om 6:18 heeft Robert Sneidar het volgende geschreven:
> Am I correct in stating that variables in a custom command are not
> visible to other commands and functions that it calls? In other
> words, if I put "blah" into bobtest in handler "dosomething" and
> then "dosomething" calls handler "somethingelse", is bobtest
> invisible to handler "somethingelse"? Is there any way to change
> this behavior? If not, is there any way I can lobby Runtime
> Revolution to consider adding this as a switchable option? OMHO
> children should inherit what the parent has. I see variables
> defined by a parent as objects belonging to the parent, and
> therefore should be visible to the parent.
>
> Then the local declaration would have some meaning. Declaring a
> variable as local would force the behavior that is status quo now.
> Otherwise parent variables would be visible to the handlers the
> parent calls. This seems to make more sense to me. But I suspect
> this would be a huge recoding change.
>
> I think I could mimic this behavior, but at a big performance
> penalty. I think my Foxpro port hangs on this.
>
> Bob Sneidar
> IT Manager
> Logos Management
> Calvary Chapel CM
More information about the use-livecode
mailing list