4D v12.4SET RESOURCE |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v12.4
SET RESOURCE
|
SET RESOURCE ( resType ; resID ; resData {; resFile} ) | ||||||||
Parameter | Type | Description | ||||||
resType | String |
![]() |
4-character resource type | |||||
resID | Longint |
![]() |
Resource ID number | |||||
resData | BLOB |
![]() |
New contents for the resource | |||||
resFile | DocRef |
![]() |
Resource file reference number, or current resource file, if omitted | |||||
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.
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 BLOB to longint).
During a 4D session you maintain some user preferences in interprocess variables. To save these preferences from session to session, you can:
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
If the resource is written, OK is set to 1. Otherwise, it is set to 0 (zero).
Product: 4D
Theme: Resources
Number:
509
Created: 4D v6