FutureBasic Logo

<<    Index    >> FutureBasic 5

Def Open   statement



Syntax:
Def Open [=] typeCreatorPascalString

Description:
This statement specifies a file type and/or creator signature which is subsequently assigned to files opened for output by FB's Open statement.

typeCreatorPascalString should be a pascal string expression of either 4 or 8 characters in length. The first 4 characters specify the file type. The second group of 4 characters, if included, specifies a file creator signature for newly opened files. Once executed, a typeCreatorPascalString remains in effect until another Def Open statement is executed.

A Macintosh file may have 4-character file type and a 4-character creator signature but Apple now discourages their use and recommends other approaches (See Note 2). The file type is usually used to signify the general format of the file's contents. If you're creating a file which is to be opened by another application, you should use a file type which the other application recognizes. Otherwise, you can make up a custom file type for your program's private use.

A file's creator signature usually signifies which application created the file. The Finder uses the file's creator signature to determine such things as: which application to launch when the user double-clicks the file's icon. The Finder uses the file's creator signature, in combination with the file's type, to determine the icon to display for the file. By default, if your program hasn't yet executed a Def Open statement with a non-NULL typeCreatorPascalString parameter, FutureBasic assigns a NULL( OSType equal to zero ) type and creator signature to files opened for output. Specifying a zero length typeCreatorPascalString ( such as Def Open "" ) also results in a NULL type and creator.

Example:
Def Open "ttrottxt"
Open "O", #1, "test file",@parentFolderRef // an FSRef cannot be created for a non-existent file, so a filename is supplied
Print #1, "This is a test file"
Close #1


The program above creates a file whose type is "ttro" and whose creator signature is "ttxt". The Finder recognizes such a file as a SimpleText "read-only" text file. The file will appear with an appropriate icon, and the Finder will launch SimpleText when the user double-clicks the file's icon.

Note:
(1) Def Open only applies to files which are opened with the "O" option. It does not change the type nor creator signature of files which are opened for input only ("I") or for random access ("R").
(2) Apple has recommended use of Uniform Type Identifiers to replace Type/Creator. See Apple's "Introduction to Uniform Type Identifiers" for more information.


See Also:
files$; open