Bernie a écrit : > > I'm not very good with resources but I've cobbled this together with > bits and pieces from the CD. It appears to work but maybe some of the > other guys could cast their eyes over it and correct any errors. > > Bernie > > > '---------- > include "Subs PrefsFile.incl" > > _myPrefsFileName$ = "BackUp Prefs" > _mySTRid = 128 > > dim s as Str255 > stringlist on > stringlist = _mySTRid, "strings" > s = "One Too Many Mornings" > s = "Two Trains Running" > s = "Three Angels" > s = "Fourth Time Around" > s = "Absolutely Five Believers" > s = "From a Buick Six" > s = "Seven Days" > s = "Freight Train Blues" > s = "Ninety Miles an Hour" > s = "True Love Tends to Forget" > stringlist end > > > begin record MyPrefs > dim as Str255 myString > dim as Boolean myBoolean > end record > dim as MyPrefs myPrefs > > > local mode > local fn STRResToPrefsRes( prefsFileName as Str255, strID as long ) > '~'1 > dim as FSSpec fsSpec > dim as Handle h, resH > dim as long @ dirID > dim as short prefsResRef, oldResRef, @ vRefNum > dim as OSErr err > > long if ( fn FindFolder( _kOnAppropriateDisk, _kPreferencesFolderType, > _kDontCreateFolder, @vRefNum, @dirID ) == _noErr ) > long if ( fn FSMakeFSSpec( vRefNum, dirID, prefsFileName, fsSpec ) == > _noErr ) > prefsResRef = fn FSpOpenResFile( fsSpec, _fsRdWrPerm ) > long if ( prefsResRef != -1 ) > > oldResRef = fn CurResFile > UseResFile( system( _aplRes ) ) > h = fn Get1Resource( _"STR#", strID ) > long if ( h ) > resH = Usr ReplaceResource( h, _"STR#", strID, "", prefsResRef ) > DisposeHandle( h ) > end if > UseResFile( oldResRef ) > CloseResFile( prefsResRef ) > > end if > end if > end if > end fn > > > myPrefs.myString = "My prefs string" > myPrefs.myBoolean = _true > put preferences _myPrefsFileName$, myPrefs > > fn STRResToPrefsRes( _myPrefsFileName$, _mySTRid ) > > do > HandleEvents > until gFBQuit > '---------- Since you get a resource handle to a STR# resource (stored in the app file), I think you must use ReleaseResource instead of DisposeHandle. Usr ReplaceResource returns the handle, so you could write: h = fn Get1Resource( _"STR#", strID ) if h then ReleaseResource( Usr ReplaceResource( h, _"STR#", strID, "", prefsRef ) Alain Alain