A command to clear all globals

Something you want to see in a LiveCode product? Want a new forum set up for a specific topic? Talk about it here.

Moderator: Klaus

Post Reply
tonymac
Posts: 23
Joined: Thu Jan 05, 2012 9:17 pm

A command to clear all globals

Post by tonymac » Fri Mar 02, 2012 10:19 pm

I sure could use a single command that would "ClearAllGlobals". Wow... that's it, clearGlobals. That would make my coding and debugging life so much more simple in so many ways.

Thanks.

Gene
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 75
Joined: Wed Mar 09, 2011 6:48 pm

Re: A command to clear all globals

Post by Gene » Fri Mar 02, 2012 11:29 pm

Try looking up the keyword "Globals" in the dictionary. There is both a command, and a function, described that are supposed to return a list of all globals. I would try a simple repeat routine that rampages through the list and deletes them one at a time from start to finish. It seems awkward compared to a simple built-in "clearGlobals" command, but you could always put your script into a custom function called "clearGlobals" and keep it to drop into each new project, ready to go.

A brief look at the documentation suggests that it would be a good thing to check out the other references pertaining to deleting variables before called it done.

Gene

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: A command to clear all globals

Post by mwieder » Fri Mar 02, 2012 11:41 pm

Additionally, I avoid problems with global variables by avoiding the use of global variables.

If you absolutely need this you might try

before doing anything with global variables:

Code: Select all

put the globals into sGlobals
then when you want to clean them

Code: Select all

on clearGlobals
  put the globals into tGlobalList
  repeat for each line tGlobal in tGlobalList
    if tGlobal is not among the lines of sGlobals then
      global tGlobal
      delete variable tGlobal
    end if
  end repeat
end clearGlobals

Post Reply