[futurebasic] Re: [Q] Resource Manager

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : March 1998 : Group Archive : Group : All Groups

From: Mars Saxman <marssaxman@...>
Date: Mon, 2 Mar 98 15:34:29 -0800
Mel:

>I have been working on a project for the last few months. It has an
>external resource file and to make sure that I don't get a collision, I
>open the external resource file, use the toolbox USERESREF(filenumb) to
>switch to it and then extract my resource using GET1RESOURCE (again from
>the toolbox).

The problem is that USERESREF changes the resource file list, which is a 
side effect that can cause problems. Never change the resource file list 
if you can possibly help it.

Instead, I'd recommend using a "passive" approach. Call GETRESOURCE and 
let the system load whatever resource it wants to. Then use FN 
HOMERESFILE to get the file number the just-loaded resource comes from. 
If it's not your file, ignore it.

Another way to avoid conflict might be something like this:

DIM oldRes%
oldRes% = FN CURRESFILE
CALL USERESFILE(gMyResFile%)
..load the resource...
CALL USERESFILE(oldRes%)

>Secondly, when you read in a resource from an external file, and then close
>the external file, is the handle still valid in memory or does closing the
>external file remove all references to anything it might have contained?
>All my external resources are marked purgeable so maybe the memory manager
>is doing what it's supposed to do when you close an external resource file.

All resources are dumped when you close the resource file that owns them. 
To keep a resource handle around no matter what, use DETACHRESOURCE on 
the handle. This turns the resource handle into an ordinary handle, so it 
is no longer attached to the resource file.

-Mars