Beijer Electronics (formerly QSI Corporation)

Manufacturer of Mobile Data and Human Machine Interface Terminals.
It is currently Sun Nov 19, 2017 8:57 am

All times are UTC - 7 hours




Post new topic Reply to topic  [ 16 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Persisting variables
PostPosted: Fri Mar 18, 2011 2:10 pm 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
Unlike many other languages, arrays in Qlarity resize dynamically. The net effect is that if you declare an array with 10 elements, that is just its initial size. The actual number of elements may increase or decrease at run time depending on what operations you run on it.

Common ways that an array will change size is performing an assignment to it (you probably do this all the time with strings) and calling redim() on it. There are a few other ways that it can happen as well, all in response to a few API calls that manipulate arrays.

In the case of your example, when the Save method is called and your array is persisted, the PersistentVariables object will save out however many elements your array currently has (this would be five, assuming that you never do anything to that array to change its size).

When you restore the persisted data, the array will resize to whatever size it was persisted as. In your example, it would shrink back down to five elements.

You did bring up a point to be careful with when using persisted variables -- if your program changes over time, you need to be sensitive to ways old persisted variables can break things.

For example, if you remove a variable from your program that was previously persisted, you will get an exception during the restore.

In your case, you should probably handle the RestoreComplete event and do something to ensure that your array has valid data. One possibility would be to do

redim(myArray, 10)

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page Previous  1, 2

All times are UTC - 7 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group