[futurebasic] Re: [FB] Preferences File

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : August 2005 : Group Archive : Group : All Groups

From: Michael Evans <michaelevans_01@...>
Date: Mon, 1 Aug 2005 20:29:19 -0400
how would one load from multiple text file(s) to a set of str# 
resources in a single prefs file?


On Aug 1, 2005, at 05:04 PM, Alain Pastor wrote:

> 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
>
> --
>
>
Cheers,

-----------------------------------------------------------------
Michael Evans <michaelevans_01@...>
3301 Wood Valley Rd, NW • Atlanta, GA 30327-1515
V: (404) 846-9386 • Cell: (404) 229-3930
[SFSG] [HBPW]
-----------------------------------------------------------------