4D v14.3On Exit database method |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v14.3
On Exit database method
On Exit database method
The On Exit database method is called once when you quit a database. This method is used in the following 4D environments:
Note: The On Exit database method is NOT invoked by 4D Server. The On Exit database method is automatically invoked by 4D; unlike project methods, you cannot call this database method yourself by programming. You can however execute it from the Method editor. You can also use subroutines. A database can be exited if any of the following occur:
No matter how the exit from the database was initiated, 4D performs the following actions:
The On Exit database method is the perfect place to:
Note: Don’t forget that the On Exit database method is a local/client process, so it cannot access the data file. Thus, if the On Exit database method performs a query or a sort, a 4D Client that is about to quit will "freeze" and actually will not quit. If you need to access data when a client quits the application, create a new global process from within the On Exit database method, which will be able to access the data file. In this case, be sure that the new process will terminate correctly before the end of the On Exit database method execution (by using interprocess variables, by example). The following example covers all the methods used in a database that tracks the significant events that occur during a working session and writes a description in a text document called “Journal.”
` On Startup Database Method
` WRITE JOURNAL Project Method Note that the document is open and closed each time. Also note the use of a semaphore as “access protection” to the document—we do not want two processes trying to access the journal file at the same time.
` M_ADD_RECORDS Project Method This method loops until the user cancels the last data entry or exits the database.
` [Table1];"Input" Form Method
` M_QUIT Project Method The method uses a trick. When QUIT 4D is called, the command has an immediate effect. Therefore, the process from which the call is issued is in “stop mode” until the database is actually exited. Since this process can be one of the processes in which data entry occurs, the call to QUIT 4D is made in a local process that is started only for this purpose. Here is the DO_QUIT method: ` DO_QUIT Project Method
` On Exit Database Method Note: Processes that have names beginning with "ML_..." or "M_..." are started by menu commands for which the Start a New Process property has been selected. In this example, these are the processes started when the menu command Add record was chosen. The test (Current time-$vhStart)>=?00:01:00? allows the database method to get out of the “waiting the other process” Repeat loop if the other process does not act immediately. The following is a typical example of the Journal file produced by the database:
Note: The name $xx is the name of the local process started by 4D in order to execute the On Exit database method. |
PROPERTIES
Product: 4D
HISTORY
Created: SEE ALSO
On Startup database method ARTICLE USAGE
4D Language Reference ( 4D v11 SQL Release 6) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||