[futurebasic] Re: [FB] Util_CFPrefsCFStrings - funky results in plist

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

From: Thomas Peters <thomasg_peters@...>
Date: Tue, 9 Aug 2011 15:32:54 -0400
Quorking.... HAHAAHHA

On 8/9/11 3:29 PM, "Thomas Peters" <thomasg_peters@...> wrote:

>The whole purpose for this exercise is to be able to dynamically set the
>values for the following:
>
><snippet>
>
>clear local
>local fn mysqlConnect
>
>BeginCFunction
>
>     Boolean ok;
>     char hostChar[ 80 ];
>     char usernameChar[ 80 ];
>     char passwordChar[ 80 ];
>     char schemaChar[ 80 ];
>
>     ok = CFStringGetCString( host, hostChar, 80, kCFStringEncodingUTF8 );
>     ok = CFStringGetCString( username, usernameChar, 80,
>kCFStringEncodingUTF8 );
>     ok = CFStringGetCString( password, passwordChar, 80,
>kCFStringEncodingUTF8 );
>     ok = CFStringGetCString( schema, schemaChar, 80,
>kCFStringEncodingUTF8 );
>
>     if (NULL == mysql) {
>          mysql = mysql_init( NULL );
>          // 
>mysql_real_connect(mysql,"localhost","tpeters","river123","process_engine"
>,
>0,NULL,0);
>          mysql_real_connect(mysql, hostChar, usernameChar, passwordChar,
>schemaChar, 0, NULL, 0);  //   <<<   here
>     }
>EndC
>
>end fn
>
></snippet>
>
>I have the 4 CFStringRef objects dimensioned in myprefs.glbl file.  The
>functions: Accessor: GetMySQLPrefs & Mutator: SetMySQLPrefs are now
>qorking with the suggestion from Bernie, Brian and Deep... Thanks guys...
>
>The above code has a C Function because the mysql APIs that I am using are
>in C.  they work when I hard code the parameters, but I am trying to
>create a dynamic preference that allows end users to set their own
>connection properties in my preference window.
>
>Thanks in advance... I realize this is border-line off topic.  Hope
>someone can address this.
>
>Thomas
>
>
>
>On 8/9/11 2:27 PM, "Thomas Peters" <thomasg_peters@...> wrote:
>
>>Thanks so much all for helping me out here ...
>>
>>-----Original Message-----
>>From: Bernie
>>Sent: Tuesday, August 09, 2011 12:56 PM
>>To: futurebasic@...
>>Subject: Re: [FB] Util_CFPrefsCFStrings - funky results in plist
>>
>>
>>Thomas Peters wrote:
>>
>>> Getting some funky behavior from Util_CFPrefsCFStrings.incl functions.
>>>I
>>> am trying to setup a preferences file for an app I am working on.  :-)
>>> Can you guess?  It's for the login information for MySQL connection!  I
>>>am
>>> getting some very strange results in my plist.  I guess I do not
>>> understand the way pointers work, because it looks like the values are
>>> getting mashed together...
>>>
>>> clear local
>>> local fn getMySQLPrefs
>>> dim string as Str255
>>> dim strLen as CFIndex
>>>
>>> // host = fn CFStringCreateMutable( _kCFAllocatorDefault, 0 )
>>> // username = fn CFStringCreateMutable( _kCFAllocatorDefault, 0 )
>>> // password = fn CFStringCreateMutable( _kCFAllocatorDefault, 0 )
>>> // schema = fn CFStringCreateMutable( _kCFAllocatorDefault, 0 )
>>>
>>> host = fn CFPrefsCopyAppValue( @"mySQLHost" )
>>> strLen = fn CFStringGetLength( host )
>>> string = ""
>>> fn CFStringGetPascalString( host, @string, strLen,
>>>_kCFStringEncodingASCII
>>> )
>>> fn SetButtonTextString( _hostEdit, string )
>>>
>>> username = fn CFPrefsCopyAppValue( @"mySQLUsername" )
>>> strLen = fn CFStringGetLength( username )
>>> string = ""
>>> fn CFStringGetPascalString( username, @string, strLen,
>>> _kCFStringEncodingASCII )
>>> fn SetButtonTextString( _usernameEdit, string )
>>>
>>> password = fn CFPrefsCopyAppValue( @"mySQLPassword" )
>>> strLen = fn CFStringGetLength( password )
>>> string = ""
>>> fn CFStringGetPascalString( password, @string, strLen,
>>> _kCFStringEncodingASCII )
>>> fn SetButtonTextString( _passwordEdit, string )
>>>
>>> schema = fn CFPrefsCopyAppValue( @"mySQLSchema" )
>>> strLen = fn CFStringGetLength( schema )
>>> string = ""
>>> fn CFStringGetPascalString( schema, @string, strLen,
>>> _kCFStringEncodingASCII )
>>> fn SetButtonTextString( _schemaEdit, string )
>>>
>>> end fn
>>>
>>> clear local
>>> local fn setMySQLPrefs
>>>
>>> dim string as Str255
>>>
>>> string = ""
>>> string = fn ButtonTextString$( _hostEdit )
>>> host = fn CFStringCreateWithCString(_kCFAllocatorDefault, string,
>>> _kCFStringEncodingASCII)
>>> fn CFPrefsSetAppValue( @"mySQLHost", host )
>>>
>>> string = ""
>>> string = fn ButtonTextString$( _usernameEdit )
>>> username = fn CFStringCreateWithCString(_kCFAllocatorDefault, string,
>>> _kCFStringEncodingASCII)
>>> fn CFPrefsSetAppValue( @"mySQLUsername", username )
>>>
>>> string = ""
>>> string = fn ButtonTextString$( _passwordEdit )
>>> password = fn CFStringCreateWithCString(_kCFAllocatorDefault, string,
>>> _kCFStringEncodingASCII)
>>> fn CFPrefsSetAppValue( @"mySQLPassword", password )
>>>
>>> string = ""
>>> string = fn ButtonTextString$( _schemaEdit )
>>> schema = fn CFStringCreateWithCString(_kCFAllocatorDefault, string,
>>> _kCFStringEncodingASCII)
>>> fn CFPrefsSetAppValue( @"mySQLSchema", schema )
>>>
>>> end fn
>>>
>>
>>In your set function, you should be using CFStringCreateWithPascalString.
>>
>>Here's another way to do it (N.B. CFPrefsCopyAppValue and HIViewCopyText
>>both contain the word "Copy" so string should be released):
>>
>>'---------------
>>include "Tlbx HIView.incl"
>>
>>local mode
>>local fn GetMySQLPrefs
>>'~'1
>>dim as CFStringRef   string
>>
>>string = fn CFPrefsCopyAppValue( @"mySQLHost" )
>>long if ( string )
>>fn HIViewSetText( button&( _hostEdit ), string )
>>CFRelease( string )
>>end if
>>
>>string = fn CFPrefsCopyAppValue( @"mySQLUsername" )
>>fn HIViewSetText( button&( _usernameEdit ), string )
>>CFRelease( string )
>>
>>string = fn CFPrefsCopyAppValue( @"mySQLPassword" )
>>fn HIViewSetText( button&( _passwordEdit ), string )
>>CFRelease( string )
>>
>>string = fn CFPrefsCopyAppValue( @"mySQLSchema" )
>>fn HIViewSetText( button&( _schemaEdit ), string )
>>CFRelease( string )
>>end fn
>>
>>local mode
>>local fn SetMySQLPrefs
>>'~'1
>>dim as CFStringRef   string
>>
>>string = fn HIViewCopyText( button&( _hostEdit ) )
>>fn CFPrefsSetAppValue( @"mySQLHost", string )
>>CFRelease( string )
>>
>>string = fn HIViewCopyText( button&( _usernameEdit ) )
>>fn CFPrefsSetAppValue( @"mySQLUsername", string )
>>CFRelease( string )
>>
>>string = fn HIViewCopyText( button&( _passwordEdit ) )
>>fn CFPrefsSetAppValue( @"mySQLPassword", string )
>>CFRelease( string )
>>
>>string = fn HIViewCopyText( button&( _schemaEdit ) )
>>fn CFPrefsSetAppValue( @"mySQLSchema", string )
>>CFRelease( string )
>>end fn
>>'---------------
>>
>>
>>or a bit neater?..
>>
>>'---------------
>>include "Tlbx HIView.incl"
>>
>>local mode
>>local fn PrefsValeToButtonText( key as CFStringRef, btn as long )
>>'~'1
>>dim as CFStringRef   string
>>
>>string = fn CFPrefsCopyAppValue( key )
>>long if ( string )
>>fn HIViewSetText( button&( btn ), string )
>>CFRelease( string )
>>end if
>>end fn
>>
>>local mode
>>local fn GetMySQLPrefs
>>'~'1
>>fn PrefsValeToButtonText( @"mySQLHost", _hostEdit )
>>fn PrefsValeToButtonText( @"mySQLUsername", _usernameEdit )
>>fn PrefsValeToButtonText( @"mySQLPassword", _passwordEdit )
>>fn PrefsValeToButtonText( @"mySQLSchema", _schemaEdit )
>>end fn
>>
>>local mode
>>local fn ButtonTextToPrefsValue( btn as long, key as CFStringRef )
>>'~'1
>>dim as CFStringRef   string
>>
>>string = fn HIViewCopyText( button&( btn ) )
>>long if ( string )
>>fn CFPrefsSetAppValue( key, string )
>>CFRelease( string )
>>end if
>>end fn
>>
>>local mode
>>local fn SetMySQLPrefs
>>'~'1
>>fn ButtonTextToPrefsValue( _hostEdit, @"mySQLHost" )
>>fn ButtonTextToPrefsValue( _usernameEdit, @"mySQLUsername" )
>>fn ButtonTextToPrefsValue( _passwordEdit, @"mySQLPassword" )
>>fn ButtonTextToPrefsValue( _schemaEdit, @"mySQLSchema" )
>>end fn
>>'---------------
>>
>>Bernie
>>
>>
>>
>>
>>--
>>To unsubscribe, send ANY message to:
>>futurebasic-unsubscribe@...
>>To access the list archives, go to:
>>http://freegroups.net/groups/futurebasic/
>>
>>
>>--
>>To unsubscribe, send ANY message to:
>>futurebasic-unsubscribe@...
>>To access the list archives, go to:
>>http://freegroups.net/groups/futurebasic/
>>
>>
>
>
>
>--
>To unsubscribe, send ANY message to: futurebasic-unsubscribe@...
>To access the list archives, go to:
>http://freegroups.net/groups/futurebasic/
>
>