saveandclose
saveandclose
DATABASE
,
DELAY

The saveandclose statement saves and closes a database file.

Parameters

This statement has two parameters:

database – name of the database you want to save and close (or `""` to close the current database).

delay – delay before the database is closed (if this parameter is omitted, the default is 3 seconds).

Description

This statement saves and then closes a database file. This is recommended instead of performing these operations with separate consecutive statements. So instead of this:

    save
    closefile

the recommended code is:

    saveandclose ""

You can also save and close a database that is not currently the topmost database, or even a database that doesn’t have any windows open.

    saveandclose "Price List"

Technical Note: Panorama uses Apple’s NSDocument framework to manage database operations, including saving the database. When you save a database, NSDocument performs this operation asynchronously. This means that it will save in the background, while your procedure continues on with the next task. If the next task is closing the database, this can cause problems because the document will close before the save is complete.

To solve this problem, the saveandclose statement performs this sequence of steps.

- Unlock any locked records.
- If the database is shared, disconnect it from the server.
- Start the save operation.
- Close any open database windows (in other words, make the database secret).
- Wait 3 seconds (this delay can be adjusted).
- Close the database (remove it from memory).

In other words, the database will appear to close immediately, but it isn’t actually removed from RAM for 5 seconds. This gives the save operation time to complete. You can also add a second parameter to adjust the time delay, for example this code will use a delay of 10 seconds.

    saveandclose "",10

However, I wouldn’t recommend making the time too long. For example, suppose you made it 60 seconds, but then 20 seconds after running this statement you opened the database again. You’ll probably be surprised when the database closes again 40 seconds later!

Keep in mind that Panorama uses a timer to remove the database from memory, so the specified delay is the minimum time. It could be longer. For example, if you use saveandclose and then the procedure continues to do further processing for an additional 30 seconds, the database won’t actually be removed from memory until after all of that processing is complete.

See Also

- Auxiliary Databases -- automatically opening multiple databases associated with each other.
- closedatabase -- closes a specified database.
- closefile -- closes the current database.
- closeserverfile -- closes the current database (used on the server).
- Custom Database Initialization -- using an .Initialize procedure to automatically run custom code when a database opens.
- Database Integrity Checks -- checking database integrity when opening and saving.
- Database is Damaged Alert -- how to fix the "database is damaged" alert when opening a database.
- opendatabase -- opens a database file.
- openfile -- opens a database file. It can also import data from a text file, another database, or a variable into the current database.
- opensavedwindows -- opens windows that were open the last time file was saved.
- opensecret -- opens a database invisibly, without opening its windows.
- openserverfile -- opens a database (used on the server).
- opentextfile -- imports data from a text file or a variable into the current database.
- panoramastartupdatabases -- opens any databases specified for startup.
- save -- saves the database to disk.

History

Version | Status | Notes
10.2 | New | New in this version.