[futurebasic] Re: [FB] Deleting Resource

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 1999 : Group Archive : Group : All Groups

From: Joe Lewis Wilkins <PepeToo@...>
Date: Sun, 28 Nov 1999 08:10:25 -0800
Phil Yates wrote:

> I have a requirement to run a program that replaces certain STR# resources
> in an Application program (APPL) file.
>
> I created a resource (rsrc) file to try this, and it works fine. But if I
> try this on an APPL, it doesn't delete the old resource - it just appends
> the new strings onto the end of the old Resource. The code I'm using is :
>
> gOutputResFile  = FN OPENRFPERM(DataFile$,DataVol%,_fswrperm)
> CALL USERESFILE(gOutputResFile)
> Rsrc = _TypeMarker
> OldResHndl& = FN GET1RESOURCE(CVI("STR#"),Rsrc)
> LONG IF OldResHndl&
>   CALL RMVERESOURCE(OldResHndl&)
>   CALL UPDATERESFILE(gOutputResFile)
> END IF
> FN AddStr2List(Rsrc,"YES - Types","Types")
> Temp$ = MID$(STR$(TypeCount),2)
> FN AddStr2List(Rsrc,Temp$,"")
>
> Anyone suggest what I'm doing wrong ?
> Or more likely, what else I have to do ?

Good Day Phil,

One thing I noticed is that you've not done any error checking. Though I have
rarely encountered any errors AFTER I got a FN working properly, it frequently
let me see when I was NOT doing any one particular part correctly. Most
Resource calls should be checked to prevent program failure in the event
someone messes around with them.

When doing this, I recall having gotten a count of the strings with:
strH& = FN GETRESOURCE(_"STR#",resID%)
rStrs% = ([strH&])

and then removing all of the strings with a FOR NEXT loop and DEF
REMOVESTR(strH&,i%),
calling CHANGERESOURCE(strH&), checking for errs with err% = FN RESERROR
and, if err% = _noErr, calling WRITERESOURCE(strH&); otherwise putting up an
Alert.

I would then add the "new" strings with a series of calls to DEF
APNDSTR(aStr$,strH&), followed by a call to CHANGEDRESOURCE(strH&) , checking
again for errs with err% = FN RESERROR
and, if err% = _noErr, calling WRITERESOURCE(strH&) and
RELEASERESOURCE(strH&); otherwise putting up an Alert.

I don't remember why I did this, but it works; and, unless the number of
strings is extremely long, the time needed to do this is negligible. It just
may be that RMVERESOURCE isn't/wasn't supported by FB. I can't think of any
other reason I would have gone to such lengths; since, in some cases, where I
wanted to retain some of the existing strings I had to save them in arrays of
strings and then "reappend" them to the Resource later on.

I still haven't discovered the secret to adding Toolbox calls that are not
supported by FB. Anyone having developed that expertise - I know it's in the
Manuals, I could just never get it to work (I think!) - would be a welcome
post. If this is all too muddy for you, I can send you a series of FNs
directly if you'd like.

Joe Wilkins