4D v12.4

Create resource file

Home

 
4D v12.4
Create resource file

 

Create resource file 


 

Create resource file ( resFilename {; fileType {; *}} ) -> Function result 
Parameter Type   Description
resFilename  String in Short or long name of resource file, or empty string for standard Save File dialog box
fileType  String in Mac OS file type (4-character string), or Windows file extension (1- to 3-character string), or Resource ("res " / .RES) document, if omitted
in If passed = Use data fork
Function result  DocRef in Resource file reference number

The Create resource file command creates and opens a new resource file whose name or pathname is passed in resFileName.

If you pass a file name, the file will be located in the same folder as the structure file of the database. Pass a pathname to create a resource file located in another folder.

If the file already exists and is not currently open, Create resource file overrides it with a new empty resource file. If the file is currently open, an I/O error is returned.

If you pass an empty string in resFileName, the Save File dialog box is presented. You can then choose the location and the name of the resource file to be created. If you cancel the dialog, no resource file is created; Create resource file returns a null DocRef and sets the OK variable to 0.

If the resource file is correctly created and opened, Create resource file returns its resource file reference number and sets the OK variable to 1. If the resource file cannot be created, an error is generated.

On Macintosh, the default file type for a file created with Create resource file is “res ”. On Windows, the default file extension is “.res”. To create a file of another type:

  • On Macintosh, pass the file type in the optional parameter fileType.
  • On Windows, in fileType, pass a 1- to 3-character Windows file extension or a Macintosh file type mapped using the MAP FILE TYPES command.

By default, if the * parameter is omitted, the command creates and opens the file resource fork. When this parameter is passed, the command creates and opens the file data fork (readable on both Mac OS and Windows platforms). For more information, refer to the Resources topic.

Remember to call CLOSE RESOURCE FILE for the resource file. Note, however, when you quit the application (or open another database), 4D automatically closes all the resource files you opened using Create resource file or Create resource file.

The following example tries to create and open on Windows, the resource file “MyPrefs.res” located in the database folder:

 $vhResFile:=Create resource file("MyPrefs";*)

On Macintosh, the example tries to create and open the file “MyPrefs”.

The following example tries to create and open, on Windows, the resource file “MyPrefs.rsr” located in the database folder:

 $vhResFile:=Create resource file("MyPrefs";"rsr")

On Macintosh, the example tries to create and open the file “MyPrefs”.

The following example displays the Save File dialog box:

 $vhResFile:=Create resource file("")
 If(OK=1)
    ALERT("You just created “"+Document+"”.")
    CLOSE RESOURCE FILE($vhResFile)
 End if

If the resource file is successfully created and opened, the OK variable is set to 1. If the resource file could not be created or if the user clicked Cancel in the Save File dialog box, the OK variable is set to 0 (zero).

If the resource file is successfully created and opened through the Save File dialog box, the Document variable is set to the pathname of the file.

If the resource file could not be created or opened due to a resource or I/O problem, an error is generated. You can catch this error with an error-handling method installed using ON ERR CALL.

 
PROPERTIES 

Product: 4D
Theme: Resources
Number: 496

The OK variable is changed by the commandThis command modifies the system Document variableThis command modifies the Error system variable

 
HISTORY 

Modified: 4D 2004

 
SEE ALSO 

CLOSE RESOURCE FILE
ON ERR CALL
Open resource file
Resources