Main stack custom property

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Main stack custom property

Post by phaworth » Fri Jun 04, 2010 6:24 pm

I have a strange situation going on with a custom property of my app's main stack.

I use a custom property named dbFile in the main stack of my app to store the file path to the sqlite database used by my app. At start up I use it's contents to open the database.

I have an Open option on my apps File menu which presents the user with a file open dialog so they can open a different database. After they select the new database and I successfully open it, I store the file path to the database into the dbFile custom property of my main stack (and save the main stack) so that next time they run the app, it will use the last database they chose. I can see from the Inspector for the main stack that the custom property is updated correctly.

This all works perfectly in the development environment but fails miserably in a standalone application. The standalone opens the correct database at startup and when I open a different database, it opens that correctly and I can see from answer information statements in my code that the dbFile custom property of the main stack is set correctly (the anser comes after I set the dbFile custom property and save the stack). However, if I exit the standalone and run it again, it opens the original database, not the one chosen by the user with the File menu Open option. It's as if the dbFile custom property of the main stack was not saved, even though I can see that it was from my answer statements (plus it works fine in the development environment).

Either I'm missing something obvious or there is something weird about making changes to custom properties of the main stack in a standalone app.

Any ideas?

Pete

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Main stack custom property

Post by Klaus » Fri Jun 04, 2010 6:31 pm

Hi Pete,

standalones cannot save themselves, never!

You need to store the users choice in a text file, maybe in the users prefs folder.
Check some "specialfolderpath" codes in the docs and see some more of them here:
http://www.sonsothunder.com/devres/revo ... ile010.htm

I ususally use
-> specialfoderpath("preferences")
on the Mac and
-> specialfoderpath(26)
on Windows systems and always create a subfolder there, so it looks a bit cleaner :-)


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Main stack custom property

Post by dunbarx » Fri Jun 04, 2010 7:44 pm

Or you can make a new stack the mainstack and make your working stack its substack. Then changes to the substack will be saved. The mainStack (which is the executable that cannot save changes) is usually a splash screen, but can be completely hidden if you want.

Craig Newman

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: Main stack custom property

Post by phaworth » Sat Jun 05, 2010 4:48 pm

Thanks Klaus and Craig. I remember seeing somewhere that data could not be saved to a standalone but I thought that applied to data entered into a card, not internal settings like custom properties. My application stores it's data in an sqlite database so this is the first time I've run into this issue.

Just to be sure I understand this completely, it's just the main stack that can't be saved, right? If I were to save this custom property to a substack, all would work fine?

I have to say that it seems like there should be some sort of warning in the IDE or a runtime error in the standalone when Rev code executes that tries to do something like this, but I guess that's just another quirk in this weird beast we call Revolution!

Once again, thanks for your help,

Pete

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

Re: Main stack custom property

Post by mwieder » Sun Jun 06, 2010 2:33 am

Just to be sure I understand this completely, it's just the main stack that can't be saved, right? If I were to save this custom property to a substack, all would work fine?
No. The only way that would work is if the substacks were separate *files*.

It's not a runrev thing, it's an OS thing. Making changes to stacks in the standalone is the equivalent to modifying a running application, and no modern OS will allow that.

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: Main stack custom property

Post by phaworth » Sun Jun 06, 2010 7:38 pm

Thanks Mark.

I'm now finding other places where I store custom property values that need to survive across runs of my app. Some of them lend themselves to using an external preferences file and some don't so I need to implement the solution involving multiple stack files. If I'm understanding this correctly, I need to make a single stack file that does nothing except open my real stack file and the single stack file is the one I use to build my application. In the single stack, I assume I use go stack to open the real stack? Should I specify the real stack in the Stack Files property of the single stack file and/or the stacks tab of the Standalone Application Settings?

By the way, I'm not disputing that it's an OS thing rather than Revolution, I just find it strange that Revolution allows you to do things during development that apparently will not and can not work in a standalone application. And that executing a save this stack command in a standalone application doesn't throw an error. If Revolution did either of those things, I would have saved myself several hours of debugging time.

It's entirely possible that I missed something in the documentation but I haven't found any mention of the fact that stacks can't be saved in a standalone application. In fact section 10.1 of the User Guide says "All of Revolution's feature set is available for use in a standalone application". And on page 222 of the User Guide, it says "If you want to use the same setting of a global property during a different session of your application, you must save the setting - in a Preferences file, in a custom property, or elsewhere in a saved file....". Once again, not disputing that this can't be done, just bemoaning the fact that the documentation seems to be silent and contradictory on what seems to me to be an extremely important issue.

Pete

Post Reply