Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » UltraLite - AppForge Programming » Understanding UltraLite Development with AppForge » Maintaining state in UltraLite Palm applications

Understanding how state is maintained Next Page

Example: Using the persistent name to maintain state information


The PersistentName example program is a relatively simple program that shows how to use maintained state information. It is available at [external link] http://www.sybase.com/detail?id=1022734. Here are some highlights from the sample:

'MobileVB using VB6
CustomerTable.Open
AddRow "John", "Doe", "Atlanta"
AddRow "Mary", "Smith", "Toronto"
AddRow "Jane", "Anderson", "New York"
AddRow "Margaret", "Billington", "Vancouver"
AddRow "Fred", "Jones", "London"
AddRow "Jack", "Frost", "Dublin"
AddRow "David", "Reiser", "Berlin"
AddRow "Kathy", "Stevens", "Waterloo"
AddRow "Rebecca", "Gable", "Paris"
AddRow "George", "Jenkins", "Madrid"
CustomerTable.Close

This code adds ten rows to the ULCustomer table. It calls Open on the table, but in this case a persistent name is not supplied because there is no need to maintain the position in the table. Since the code only inserts data, the position in the table is not relevant.

The following line opens the ULCustomer table, ordering rows by the primary key and assigning a persistent name of customer.

CustomerTable.Open "" , "customer"

If the application has been run before, then a lookup is done in the state database for customer. Otherwise, customer is associated with this table.

The customer table is left open for the duration of the running application. If the user switches to another application, UltraLite records the position in the table where the user left off. When the application is started again, the table is opened and UltraLite determines that position information is known for a table with the persistent name customer, so it positions the user back on that row.

When the user clicks the End button, the customer table and the connection are closed before the application disappears. This has the effect of discarding any state information for the customer table, so that when the application is restarted, the user is positioned on the first row.