Problem Saving and Loading Data
Posted: Thu Aug 16, 2012 5:54 pm
I've got another LiveCode file that's been saving and loading data in the development environment and as a stand-alone for over a decade, and it seems like I'm doing the same thing with this new problem stack, but I can't get it to work. My goal is to get changes to the field "NotesField" of the card "NotesCard" of the mainstack "SchoolMAX Clipboard" to persist when the stack is closed and reopened. I'm saving the data to and loading it from field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode".
Here's the simple script of the mainstack--and darn near the only script in the whole stack:
on preOpenStack
set the blendLevel of me to 10
local itemDelimParking
local ldefaultFolder
put the fileName of me into ldefaultFolder
put the itemDelimiter into itemDelimParking
set the itemDelimiter to "/"
put "" into the last item of ldefaultFolder
put "Data" after ldefaultFolder
set the defaultFolder to ldefaultFolder
set the itemDelimiter to itemDelimParking
set the menuhistory of button "Tabs" to 1
go invisible card "NotesCard" of stack "SchoolMAX Clipboard Data.livecode" -- Must set the mainStack of this stack to itself in Property Inspector.
loadData
end preOpenStack
on remoteMouseUp -- Called by each colored button, example button "0100 GRADE PK".
set the clipboardData["text"] to the short name of the target
end remoteMouseUp
on closeStack
saveData
close stack "SchoolMAX Clipboard Data.livecode"
end closeStack
on loadData
put field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode" into field "NotesField" of card "NotesCard" of stack "SchoolMAX Clipboard"
end loadData
on saveData
put field "NotesField" of card "NotesCard" of stack "SchoolMAX Clipboard" into field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode"
end saveData
------
I don't know if that "go invisible" line is necessary at all. It's just one of the things I've tried in my troubleshooting.
The place I intend my data be saved, the stack "SchoolMAX Clipboard Data.livecode", is listed with its correct relative path (relative to mainstack SchoolMAX Clipboard") in the "Copy Files" tab of the "Standalone Application Settings" window and not listed at all in the "Stacks" tab.
The weird thing is I don't even know that this is a standalone stack problem because of the third point below:
--The loading and saving of data does not work in standalone form.
--The loading and saving of data does work in the development environment IF I close the stack by clicking its window's close button.
--The loading and saving of data does not work in the development environment if I simply quit LiveCode.
I've put in all sorts of "answer" statements (they're not there now) to ensure that, in both the developer environment and standalone mode:
--The defaultFolder is correctly set to the folder that contains "SchoolMAX Clipboard Data.livecode".
--The saveData and loadData handlers are firing when the stack opens and when it closes.
I know the saveData and loadData handlers work, too, because I've test fired them from the Message Box. If I make a change to field "NotesField" of card "NotesCard" of stack "SchoolMAX Clipboard" then fire the saveData handler from the Message Box, the change is transferred to field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode". Transferring a change the opposite way works if I fire the loadData handler in the Message Box.
This is driving me nuts. It seems so simple, but I must be doing something fundamentally wrong. It seems like I should get an error message, but I don't. Help?
Here's the simple script of the mainstack--and darn near the only script in the whole stack:
on preOpenStack
set the blendLevel of me to 10
local itemDelimParking
local ldefaultFolder
put the fileName of me into ldefaultFolder
put the itemDelimiter into itemDelimParking
set the itemDelimiter to "/"
put "" into the last item of ldefaultFolder
put "Data" after ldefaultFolder
set the defaultFolder to ldefaultFolder
set the itemDelimiter to itemDelimParking
set the menuhistory of button "Tabs" to 1
go invisible card "NotesCard" of stack "SchoolMAX Clipboard Data.livecode" -- Must set the mainStack of this stack to itself in Property Inspector.
loadData
end preOpenStack
on remoteMouseUp -- Called by each colored button, example button "0100 GRADE PK".
set the clipboardData["text"] to the short name of the target
end remoteMouseUp
on closeStack
saveData
close stack "SchoolMAX Clipboard Data.livecode"
end closeStack
on loadData
put field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode" into field "NotesField" of card "NotesCard" of stack "SchoolMAX Clipboard"
end loadData
on saveData
put field "NotesField" of card "NotesCard" of stack "SchoolMAX Clipboard" into field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode"
end saveData
------
I don't know if that "go invisible" line is necessary at all. It's just one of the things I've tried in my troubleshooting.
The place I intend my data be saved, the stack "SchoolMAX Clipboard Data.livecode", is listed with its correct relative path (relative to mainstack SchoolMAX Clipboard") in the "Copy Files" tab of the "Standalone Application Settings" window and not listed at all in the "Stacks" tab.
The weird thing is I don't even know that this is a standalone stack problem because of the third point below:
--The loading and saving of data does not work in standalone form.
--The loading and saving of data does work in the development environment IF I close the stack by clicking its window's close button.
--The loading and saving of data does not work in the development environment if I simply quit LiveCode.
I've put in all sorts of "answer" statements (they're not there now) to ensure that, in both the developer environment and standalone mode:
--The defaultFolder is correctly set to the folder that contains "SchoolMAX Clipboard Data.livecode".
--The saveData and loadData handlers are firing when the stack opens and when it closes.
I know the saveData and loadData handlers work, too, because I've test fired them from the Message Box. If I make a change to field "NotesField" of card "NotesCard" of stack "SchoolMAX Clipboard" then fire the saveData handler from the Message Box, the change is transferred to field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode". Transferring a change the opposite way works if I fire the loadData handler in the Message Box.
This is driving me nuts. It seems so simple, but I must be doing something fundamentally wrong. It seems like I should get an error message, but I don't. Help?