[futurebasic] String resource problem

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2008 : Group Archive : Group : All Groups

From: Joe Lertola <joefb@...>
Date: Thu, 17 Jan 2008 00:19:10 -0500
I have been using many functions from PG's STR# include file for years  
with great success. (I have cobbled some of them together to make the  
demo below.) Mysteriously the I have been having trouble with string  
resources over the last few weeks. In the demo below a resource file  
is opened or created and then 3 strings are saved in a STR# resource.  
This seems to work fine. I can see the strings if I open the resource  
file in Rezilla.

Subsequently when I check the number strings in the resource I get  
wrong information. The first word of the STR# resource should give the  
number of strings in the resource. But when I run the demo I get a  
number like -24474 instead of 3. I think that the call to FN  
GETRESOURCE in the fn checkResFile function must be returning bad  
information but I have no idea why. Can anyone see what the problem is  
here?

Thanks
-Joe



include "Util_Files.incl"
_tempStrList            = 4002
begin globals
dim as int gExternalResId
end globals

'~'5
local fn openOrMakeRezFile
dim as int err
DIM AS fsSpec targetSpec
dim as str255 appName$, msg$

appName$ = "MyTestRezFile.rsrc"'name of resource file to be stored in  
same folder as the program. "::::TheExtResFile"'four colons to get the  
file out of the bundle  {8/14/06}

err = fn FSMakeFSSpec( system( _aplVRefNum ), system( _aplParID ),  
appName$, @targetSpec )
print
long if Usr FSFileExists(targetSpec)
'file exists
gExternalResId = fn FSpOpenResFile( targetSpec, _fsRdWrPerm )
print "Opening external gradient resource file: " + targetSpec.name

xelse
'no file
Open "O", #1, @targetSpec'create a new resource file in the same  
folder as the app
close #1
FSpCreateResFile( targetSpec, _"GeoZ", _"GRAD", _smSystemScript )

gExternalResId = fn FSpOpenResFile( targetSpec, _fsRdWrPerm )

LONG IF gExternalResId <> 0

print  "New resource file created: "+targetSpec.name

xelse

print  "Could not open new external resource file."

end if

end if

end fn
'~'5
LOCAL FN apndElement(theID,theTxt$)
'Add an element to the end of a STR# resource.
'~'
DIM resHndl&,err,OSErr
resHndl& = FN GETRESOURCE(_"STR#",theID)
err = _noErr
LONG IF resHndl&
call HNOPURGE(resHndl&)
DEF APNDSTR(theTxt$,resHndl&)
call changedresource(resHndl&)
err = FN RESERROR
END IF
END FN = err
'~'5
local fn makeStringResource
dim as int err
dim as handle rH

rH=FN GETRESOURCE(_"STR#",_tempStrList)'delete the temp list
LONG IF rH
CALL RemoveResource(rH)
rH = _nil
print  "CALL RemoveResource executed"
xelse
print  "did not find _tempStrList"
end if

rH = FN NEWHANDLE (2)
long if rH
DEF APNDSTR("JoAnna",rH)
rH = USR ReplaceResource(rH, _"STR#", _tempStrList, "tempList",  
gExternalResId )
print "1 string resource added to resource file"

err = FN apndElement(_tempStrList,"Isaac")
long if err
print "Error could not add a string to the string resource"
xelse
print "2 string resources added to resource file"
end if

err = FN apndElement(_tempStrList,"Cleo")
long if err
print "Error could not add a string to the string resource"
xelse
print "3 string resources added to resource file"
end if

CALL UPDATERESFILE (gExternalResId)

xelse
print  "Could not make a handle"
end if

end fn
'~'5
local fn checkResFile
dim as handle resHndl&
dim as int theCount
resHndl& = FN GETRESOURCE(_"STR#",_tempStrList)
LONG IF resHndl&
theCount = {[resHndl&]}
print "The number of strings reported is " + str$(theCount)
XELSE
print  "Could not make a handle for the resource in fn checkResFile"
END IF

end fn
'~'5
window 1

fn openOrMakeRezFile
fn makeStringResource
fn checkResFile
'~'5
do
HandleEvents
until gFBQuit