[futurebasic] Re: [FB] String resource problem

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 2010 : Group Archive : Group : All Groups

From: Rich Love <carnationsoftware@...>
Date: Sun, 12 Dec 2010 09:03:29 -0600
Here is the sample program. It appears to work OK.
But when you open the resource file, ( MyTestRezFile.rsrc ), ResFool gets an error opening it and says there are 768 strings instead of 3
As I said earlier, this may be a ResFool bug. Don't know

Rich

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 FN 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&)
FN 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 NEWHANDLEclear (2)
long if rH
FN APNDSTR("JoAnna",rH)
rH = FN 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  rH
dim as short   theCount
rH = fn GetResource( _"STR#", _tempStrList )
long if ( rH )
theCount = fn CFSwapInt16BigToHost( rH..0% )
print
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




LOCAL FN LoadString (resID,theElem) as str255
dim strHndl as handle
dim count
dim size&
dim txtHndl as handle
dim offSet as long
dim src as long,dest as long
dim lgth as long
dim t$
dim x

strHndl   = FN GETRESOURCE(_"STR#",resID)

LONG IF strHndl
count = fn CFSwapInt16BigToHost( strHndl..0% )
size&    = FN GETHANDLESIZE(strHndl)-2 -count

txtHndl = FN NEWHANDLE(size&)
offSet  = 0
src     = @t$+1

LONG IF txtHndl
FOR x = 1 TO theElem
t$ = STR#(resID,x)'this is the text
lgth = LEN(t$)
dest = [txtHndl]+offSet
BLOCKMOVE src,dest,lgth
offSet = offSet + lgth
NEXT
theElem=x

END IF
xelse
t$ = ""
END IF


END FN = t$

'~'5
window 1



fn openOrMakeRezFile
fn makeStringResource
fn checkResFile

PRINT
PRINT "The Strings are:"
print fn LoadString( _tempStrList, 1 )
print fn LoadString( _tempStrList, 2 )
print fn LoadString( _tempStrList, 3 )


'~'5
do
HandleEvents
until gFBQuit




===============

On Dec 12, 2010, at 8:21 AM, Deep wrote:

> 
> Had a look at the runtime, specifically in "Subs DefUsr.incl" which does the
> heavy lifting behind the scenes for "DEF APNDSTR". Realised that it uses "fn
> apndstr" and that already performs Endian conversion for you, so the problem
> is elsewhere.
> 
> Try wiping the Resource file and start again, in case it was bad data from a
> prior attempt?
> 
> If it persists, post a quick working demo which creates your resource file
> with the bug and can look into it further.
>