App with documents

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

App with documents

Post by Mag » Wed Nov 02, 2016 5:29 pm

Hi all,

I'm creating an application that has to create docs, in them I would like to store text and some numbers. What is the best way to do this?

Is this lesson updated or with the current version of LiveCode there is a better approach? http://lessons.livecode.com/m/4071/l/70 ... n-xml-file

There you learn how to read from a XML file but there is also some tips I can use to write in it?

Unfortunately I can't use a plain document because I have also text with multiple lines and linefeeds.

Klaus
Posts: 10483
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: App with documents

Post by Klaus » Thu Nov 03, 2016 1:26 pm

Hi Mag,

why not use a (invisible) Livecode stack?
Gazillion of storing possibilities with its custom properties and custom property sets! :D


Best

Klaus

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 642
Joined: Fri Jun 27, 2008 9:00 pm

Re: App with documents

Post by Mikey » Thu Nov 03, 2016 2:24 pm

Without knowing more, a couple of thoughts:
1) The invisible stack is a good idea, especially if you don't know anything about databases, because it gives you what is, in effect, a database.
2) Look up "open file", "read from file", "write to file", and "close file". File operations in LC are stupid-simple. You don't have to limit yourself to xml, though. You can use a CSV-type format, but if you have CR's or LF's in your data, then just use some other character for the record delimiter, say ASCII(1), for instance.
3) If you know something about databases, the database routines in LC are also stupid-simple. Grab a free copy of Valentina to do your design and ad hoc queries, and eventually you'll maybe even use the Valentina ADK for reporting.

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: App with documents

Post by Mag » Thu Nov 03, 2016 5:10 pm

Klaus wrote:Hi Mag,

why not use a (invisible) Livecode stack?
Gazillion of storing possibilities with its custom properties and custom property sets! :D


Best

Klaus
Thank you Klaus, so I can store info in a stack created on the fly, save on the disk with any extension and then open it keep it invisible to get that info and to update it... seems fascinating, do you know if there is a resource online when I can learn more about this "technique"? Or do you have advices to share about it?
Last edited by Mag on Thu Nov 03, 2016 5:14 pm, edited 1 time in total.

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: App with documents

Post by Mag » Thu Nov 03, 2016 5:12 pm

Mikey wrote:Without knowing more, a couple of thoughts:
1) The invisible stack is a good idea, especially if you don't know anything about databases, because it gives you what is, in effect, a database.
2) Look up "open file", "read from file", "write to file", and "close file". File operations in LC are stupid-simple. You don't have to limit yourself to xml, though. You can use a CSV-type format, but if you have CR's or LF's in your data, then just use some other character for the record delimiter, say ASCII(1), for instance.
3) If you know something about databases, the database routines in LC are also stupid-simple. Grab a free copy of Valentina to do your design and ad hoc queries, and eventually you'll maybe even use the Valentina ADK for reporting.

Hi Mikey, thank you so much for the info about the info on the various possibilities. Very interesting the way to use some other character for the record delimiter so that I can use a text file, I did not think about it!

shaosean
Posts: 907
Joined: Thu Nov 04, 2010 7:53 am

Re: App with documents

Post by shaosean » Thu Nov 03, 2016 6:54 pm

Mag wrote:Thank you Klaus, so I can store info in a stack created on the fly, save on the disk with any extension and then open it keep it invisible to get that info and to update it... seems fascinating, do you know if there is a resource online when I can learn more about this "technique"? Or do you have advices to share about it?
I'm not Klaus, but here is the simplest way:
set the <property> of <object> to <data> // to set data
put the <property> of <object> into <container> // to get data

Let's say you were creating an address book (yeah yeah) and you had one contact per card..
stack = table
card = record
property = field

So we have our stack called "addressBook".. We're not going to bother naming the cards and will just use the numeric index.. Each contact has a first name and last name (this is a cheap address book)..

First thing we will need to do is add a new card to the stack, so we can store our contact's information..

Code: Select all

set the defaultStack to "addressBook"
create card
put it into tNewCard
Now that we have the <object> (tNewCard) we can set the contact's first and last name

Code: Select all

set the firstName of tNewCard to "Klaus"
set the lastName of tNewCard to "Major"
And now we're going to get the data for display

Code: Select all

put the firstName of tNewCard into tFirstName
put the lastName of tNewCard into tLastName
answer tFirstName && tLastName && "is pretty awesome"

Klaus
Posts: 10483
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: App with documents

Post by Klaus » Thu Nov 03, 2016 7:24 pm

Well, what not Klaus said! :D

shaosean
Posts: 907
Joined: Thu Nov 04, 2010 7:53 am

Re: App with documents

Post by shaosean » Thu Nov 03, 2016 7:51 pm

hush you awesome you :P

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: App with documents

Post by Mag » Thu Nov 03, 2016 8:41 pm

Thank you for the very clear explanation!

Code: Select all

create invisible  stack stackName
show stack stackName
is the same to

Code: Select all

create stack stackName
Or the "create invisible" command creates a special kind of object?

Klaus
Posts: 10483
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: App with documents

Post by Klaus » Thu Nov 03, 2016 8:53 pm

Hi Mag,

yep:

Code: Select all

create invisible  stack stackName
show stack stackName
=

Code: Select all

create stack stackName

Best

Klaus

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: App with documents

Post by Mag » Thu Nov 03, 2016 9:16 pm

Super! 8)

Your message contains 2 characters. The minimum number of characters you need to enter is 10.

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: App with documents

Post by Mag » Tue Nov 08, 2016 3:42 pm

So to every invisible file stack, corresponds a visible window on the screen.

How do you recommend to track pairing? Sometimes the user moves the position of a document file on the disk and in this case I would lose the file location if I had closed the invisible file stack after reading the data... :roll:

Klaus
Posts: 10483
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: App with documents

Post by Klaus » Tue Nov 08, 2016 4:59 pm

Hi Mag,
Mag wrote:So to every invisible file stack, corresponds a visible window on the screen.
I do not know your data you need to store but I do not think this is really neccessary!
Mag wrote:How do you recommend to track pairing? Sometimes the user moves the position of a document file on the disk and in this case I would lose the file location if I had closed the invisible file stack after reading the data... :roll:
Not sure what you mean!?
If a user moves any PREFS file it is the same as trashing it, means the prefs are GONE!
So store you PREF stacks in the prefs folder or any other location meant for them.


Best

Klaus

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: App with documents

Post by Mag » Tue Nov 08, 2016 9:40 pm

I would like to use one document file (a stack without scripts, just custom proprieties) for each window I create in the app. The technique described on your post in this topic.

When user close a window I save in this stack file its state, when the user opens the stack file I use the it to restore the window state.

Questions
1. Is better to close the stack file after I read on it or leave it open?
2. What happens if user moves the stack file from a location to another is there a way to know it so that I can safety save new data on it?
3. How can I know which window is associated with which stack file?

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: App with documents

Post by Mag » Fri Nov 25, 2016 4:30 pm

Klaus wrote:Hi Mag,

why not use a (invisible) Livecode stack?
Gazillion of storing possibilities with its custom properties and custom property sets! :D


Best

Klaus
I tried this approach and it's great, thank you for the suggestion. My only problem now is when user choose an integer as name for the file (or change it later on the Finder). It seems that LC confused for example stack 1, with stack with the name 1... and this complicate the handling of the document files...

http://forums.livecode.com/viewtopic.php?f=19&t=28378

Post Reply

Return to “Mac OS”