Have only used one stach so far.

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
keyless
Posts: 211
Joined: Wed Dec 12, 2007 11:21 pm

Have only used one stach so far.

Post by keyless » Mon Feb 25, 2008 10:08 pm

I've only been using one stack for programs up to now, and now find that I want to put some preference info into a substack.

in the new stack will be fields that have URL's

Handlers in the original stack need to get these URL's. I'm a little confused with how to do this. Do I have to change the handlers to point to this new stack and card someway, or will using the field name just work as before when I had the fields in the original stack?

Also I've read conflcting things, does the substack already load into memory, or do I have to open it

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Post by BvG » Mon Feb 25, 2008 10:30 pm

Substacks are part of the stack file, and always loaded at the same time as the mainstack. However, it is not shown, basically hidden. You need to make the substack active by going to it:

Code: Select all

go stack "name of substack"
As for storing stuff, there's many ways. You can put it into fields, into globals or custom properties. None of those absolutely need to be in a substack if you don't want to though. However if it's stored in a substack, you can just specify it as part of the reference:

Code: Select all

put the text of field "name of field" of stack "name of substack"
Look out though, if you want the user to save stuff, the saved data can't be in the application itself, but it will be if it's in a substack of the stack file you make the standalone out of.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

keyless
Posts: 211
Joined: Wed Dec 12, 2007 11:21 pm

Post by keyless » Tue Feb 26, 2008 12:50 am

Thank you BvG


I was going to ask if you can get data from the substack if it is not visible, but I can see that you can.

I just have one last question on this. I am going to program it so the fields in the substack save to a file. Since I am going to leve this substack as non visible should I put the code to load and save to file in the main stack or can I have it in the substack?

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Post by BvG » Tue Feb 26, 2008 12:12 pm

I am not sure what you mean, of course you can do everything in the substack that you want to do there?
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Post by FourthWorld » Tue Feb 26, 2008 9:46 pm

keyless wrote:I just have one last question on this. I am going to program it so the fields in the substack save to a file. Since I am going to leve this substack as non visible should I put the code to load and save to file in the main stack or can I have it in the substack?
Do you want a substack or a separate stack file?

If a mainstack is made into a standalone, it and any of its substacks will not be able to save changes made to them (a long-standing UNIX and Windows convention).

As a separate stackfile, you can of course save it at will.

I use something like this (off the top of my head so beware of typos):

Code: Select all

--
-- SetPref <label>,<value>
-- Used to set any arbitrary data in value to the property
-- named in label in a preferences stackfile.
--
on SetPref pLabel, pValue
  put PrefsStack() into tPrefsStack
  set the pLabel of stack tPrefsStack to pValue
  save stack pPrefsStack
end SetPref


--
-- GetPref( <label> )
-- Returns the value of the data in the property named 
-- in label in a preferences stackFile.
--
function GetPref pLabel
   put PrefsStack() into tPrefsStack
   return the pLabel of stack tPrefsStack
end GetPref


--
-- PrefsStack()
-- Returns the long path to a stack stored in the customary
-- preferences location on Mac or Windows.  If no such 
-- stack exists it will create one.
--
function PrefsStack
  put "MyApp" into tAppName
  if the platform is "Mac OS" then
    put specialFolderPath("preferences") into tPath
  else
   put specialFolderPath(26) into tPath
  end if
  put "/"& tAppName after tPath
  if there is not a folder tPath then
    create folder tPath
    if the result is not empty then
      answer "Couldn't create Preferences folder: "& tPath
      exit to top
   end if
  end if
   --
  put "/"&tAppName&"Prefs.dat" after tPath
  if there is not a stack tPath then
     -- then create an invisible one with an arbitrary name:    
    create invisible stack ("tPrefsData"&the millisecs)
    if the result is not empty then
     answer "Couldn't create Prefs file."
     exit to top
    end if
    set the fileName of it to tPath
    save stack tPath
    if the result is not empty then
      answer "Couldn't save Prefs file: OS Error code "&sysError()
      exit to top
    end if
  end if
  return tPath
end PrefsStack
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

keyless
Posts: 211
Joined: Wed Dec 12, 2007 11:21 pm

Post by keyless » Wed Feb 27, 2008 6:37 am

Hmm had not thought about just using a stack outside the executable to save. thanks for that Richard.

One question, what folder is specialFolderPath(26). The CSIDL link given in documentation doesn't exist anymore.

(This is probably the reason it no longer exists in MSDN "The CSIDL system is supported under Windows Vista for compatibility reasons. However, new development should use KNOWNFOLDERID values rather than CSIDL values")

UPDATE: I found a program called Icetips CSIDL viewer that helped. I see 26 is the Applications Data folder.




@BvG - What I was trying to get at is where should I put the Handlers for automatically saving and openening the text file. I suspect it would have to be in the Main stack, as I was thinking if I put it in the stack that will remain hidden, there really isn't a event to trigger the save, Like a open or close. Am I right on that or does the hidden stack also get the open and close events when the main stack is closed.

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”