4D v16.3

OPEN DATA FILE

Home

 
4D v16.3
OPEN DATA FILE

OPEN DATA FILE 


 

OPEN DATA FILE ( accessPath ) 
Parameter Type   Description
accessPath  String in Name or complete access path of the data file to open

The OPEN DATA FILE command allows changing the data file opened by the 4D application on-the-fly.

Pass the name or the full access path of the data file to open (file with a ".4DD" suffix) in the accessPath parameter. If you pass only the file name, it must be placed next to the structure file of the database.

If the access path sets a valid data file, 4D quits the database in progress and re-opens it with the specified data file. In single-user mode, the On Exit database method and the On Startup database method are successively called.

Warning: Since this command causes the application to quit before re-opening with the specified data file, it must be used with precaution in the On Startup database method or in a method called by this database method, so as to avoid generating an infinite loop.

The command is executed in an asynchronous manner: after its call, 4D continues executing the rest of the method. Then, the application behaves as if the Quit command was selected in the File menu: open dialog boxes are cancelled, any open processes have 10 seconds to finish before being terminated, etc.

Before launching the operation, the command checks the validity of the specified data file. Also, if the file was already open, the command verifies that it corresponds to the current structure.

If you pass an empty string in accessPath, the command will re-open the database without changing the data file.

4D Server: Beginning with 4D v13, this command can be executed with 4D Server. In this context, it makes an internal call to QUIT 4D on the server (which causes a dialog box to appear on each remote machine indicating that the server is in the process of quitting) before opening the designated file.

Example  

In the context of deploying a merged application, you want to open or create the user data file in the On Startup database method. This example uses the default data file (see Data file management in final applications):

 If(Data file="@default.4dd")
    If(Version type?? Merged application)
       If(Is data file locked)
          $dataPath:=Get 4D folder(Active 4D Folder)+"data.4dd"
  //If a local data file already exists
          If(Test path name($dataPath)=Is a document)
             OPEN DATA FILE($dataPath//open it
          Else
             CREATE DATA FILE($dataPath//create it
          End if
       End if
    End if
 End if



See also 

CREATE DATA FILE

 
PROPERTIES 

Product: 4D
Theme: 4D Environment
Number: 312

 
HISTORY 

Created: 4D v6.8
Modified: 4D v13

 
ARTICLE USAGE

4D Language Reference ( 4D v16)
4D Language Reference ( 4D v16.1)
4D Language Reference ( 4D v16.2)
4D Language Reference ( 4D v16.3)