Object

ResourceFork Class

ResourceFork Class objects are used to read and write data to resources. You can add resource files to the Project Editor (files of type "rsrc").

Properties
Geticl
Getics
ResourceLocked
ResourcePreload
ResourceProtected
ResourcePurgeable
ResourceSysHeap
TypeCount

Methods
AddPicture | GetNamedPicture | RemoveResource
AddResource | GetNamedResource | ResourceCount
Close | GetPicture | ResourceID
GetCicn | GetResource | ResourceName
GetCursor | GetSound | ResourceType
GetHandle | ReleaseHandle |

# Notes

With one exception, access to the resourcefork is supported only on Macintosh. Check the value of the TargetMacOS constant before attempting to access the resourcefork.

The one exception is that you can add custom cursors to a project using the CURS resource and access them from a Windows build. See the Notes for the MouseCursor class and the section "Custom Cursors in Windows Applications" in the User's Guide.

In built applications, all of the fields in the Get Info area of the Build Application dialog box are saved in a standard 'vers' resource. You can access this information -- such as version number, region code, and release level -- using the GetResource method of the ResourceFork class.

If you use resource numbers that conflict with internal REALbasic resources, unpredictable results may occur. One way to avoid resource ID conflicts is to choose high values, like 1128 instead of 128.

An alternate way of adding custom icons to your built application is to put your icon data (including 'icns' 32-bit icons) in a resources file that you add to your project. These icons will overwrite the icon resources supplied by REALbasic itself.

More information on the resource attribute properties (ResourceLocked, ResourcePreLoad, ResourceProtected, ResourcePurgeable, ResourceSysHeap) can be found in Apple Computer's Inside Macintosh series.

# Examples

This example sets the locked attribute of a PICT resource whose ID is 128:

Dim rf as ResourceFork
rf= GetFolderItem("MyApp").OpenResourceFork
rf.ResourceLocked("PICT",128)= True

This example checks to see if the purgable property is set

Dim rf as ResourceFork
rf= GetFolderItem("MyApp").OpenResourceFork
If rf.ResourcePurgeable("PICT",128) Then
Beep
MsgBox "This resource is purgeable."
End If

:

This example opens the project's resource fork. If you have added a resource file to your project, you can use this technique to access your resource file (assuming that the compiled application is running on Macintosh)

Dim rf as ResourceFork
rf= App.ResourceFork

:

This example gets the desktop application icon for Photoshop® and displays it in a Canvas control.

Dim rf as ResourceFork
Dim f as FolderItem
Dim p as Picture
f= GetFolderItem("Photoshop")
If f <> Nil then
rf=f.OpenResourceFork
If rf <> Nil then
p=rf.Geticl(128)
Canvas1.backdrop=p
Else
MsgBox "Resource not found!"
End if
Else
MsgBox "File not found!"
End if

This example loads a cursor from the Photoshop application and uses it as the application's cursor.

Dim rf as ResourceFork
Dim m as MouseCursor
Dimf as FolderItem
f= GetFolderItem("Photoshop")
If f <> Nil then
rf=f.OpenResourceFork
If rf <> Nil then
m=rf.GetCursor(1525)
App.MouseCursor=m
Else
MsgBox "Resource not found!"
End if
Else
MsgBox "File not found!"
End if

# See Also

App, Cursors, System objects; MouseCursor, Window class.