SET RESOURCE

4D - Documentation   Français   English   German   Spanish   4D v11 SQL, Command Theme List   4D v11 SQL, Command Alphabetical List   4D v11 SQL, Constant Theme List   Back   Previous   Next

version 6.0


SET RESOURCE (resType; resID; resData{; resFile})

ParameterTypeDescription
resTypeString4-character resource type
resIDNumberResource ID number
resDataBLOBNew contents for the resource
resFileDocRefResource file reference number, or
current resource file, if omitted

Description

The SET RESOURCE command creates or rewrites the resource whose type and ID is passed in resType and resID with the data passed in the BLOB resData.

Important: You must pass a 4-character string in resType.

If the resource cannot be written, the OK variable is set to 0 (zero).

If you pass a valid resource file reference number in resFile, the resource is added to that file. If you do not pass resFile, the resource is added to the file at the top of the resource files chain (the last resource file opened).

Note: A resource can be at least several megabytes in size.

Platform independence: Remember that you are working with Mac OS-based resources. No matter what the platform, internal resource data such as Long Integer is stored using Macintosh byte ordering. On Windows, the data for standard resources (such as string list and pictures resources) is automatically byte swapped when necessary. On the other hand, if you create and use your own internal data structures, it it up to you to byte swap the data you write into the BLOB (i.e., passing Macintosh byte ordering to a command such as LONGINT TO BLOB).

Example

During a 4D session you maintain some user preferences in interprocess variables. To save these preferences from session to session, you can:

1. Use the commands SAVE VARIABLES and LOAD VARIABLES to store and retrieve the variables in variable documents on disk.

2. Use the commands VARIABLE TO BLOB, BLOB TO DOCUMENT, DOCUMENT TO BLOB and BLOB TO VARIABLE to store and retrieve the variables in BLOB documents on disk.

3. Use the commands VARIABLE TO BLOB, SET RESOURCE, GET RESOURCE and BLOB TO VARIABLE to to store and retrieve the variables in resource files on disk.

The following is an example of the third method.

In the On Exit Database Method you write:

      ` On Exit Database Method
   If (Test path name("DB_Prefs")#Is a document)
      $vhResFile:=Create resource file("DB_Prefs")
   Else
      $vhResFile:=Open resource file("DB_Prefs")
   End if
   If (OK=1)
      VARIABLE TO BLOB(<>vbAutoRepeat;$vxPrefData)
      VARIABLE TO BLOB(<>vlCurTable;$vxPrefData;*)
      VARIABLE TO BLOB(<>asDfltOption;$vxPrefData;*)
         ` and so on...
      SET RESOURCE("PREF";26500;$vxPrefData;$vhResFile)
      CLOSE RESOURCE FILE($vhResFile)
   End if

In the On Startup Database Method you write:

      ` On Startup Database Method
   C_BOOLEAN(<>vbAutoRepeat)
   C_LONGINT(<>vlCurTable)
   $vbDone:=False
   $vhResFile:=Open resource file("DB_Prefs")
   If (OK=1)
      GET RESOURCE("PREF";26500;$vxPrefData;$vhResFile)
      If (OK=1)
         $vlOffset:=0
         BLOB TO VARIABLE($vxPrefData;<>vbAutoRepeat;$vlOffset)
         BLOB TO VARIABLE($vxPrefData;<>vlCurTable;$vlOffset)
         BLOB TO VARIABLE($vxPrefData;<>asDfltOption;$vlOffset)
            ` and so on...
         $vbDone:=True
      End if
      CLOSE RESOURCE FILE($vhResFile)
   End if
   If(Not($vbDone))
      <>vbAutoRepeat:=False
      <>vlCurTable:=0
      ARRAY STRING(127;<>asDfltOption;0)
   End if

See Also

BLOB Commands, GET RESOURCE.

System Variables and Sets

If the resource is written, OK is set to 1. Otherwise, it is set to 0 (zero).


4D - Documentation   Français   English   German   Spanish   4D v11 SQL, Command Theme List   4D v11 SQL, Command Alphabetical List   4D v11 SQL, Constant Theme List   Back   Previous   Next