[futurebasic] continued - Problem converting Pascal strings to C strings - inside CFStringRef

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

From: Thomas Peters <thomasg_peters@...>
Date: Wed, 28 Sep 2011 21:25:54 -0400
Here is an example of my problem converting from Pascal strings to C
Strings...

I need the strings to match and be able to pass the values to other
functions after conversion.

Se the ShowValueListCCode function - looking for some expertise in
creating a function that can do this for CFStringRefs, and CFNumberRef and
CFDateRef.

Thomas

'--------------   Snip


clear local
local fn CreateValueList as CFMutableDictionaryRef

dim myContainer    as CFMutableDictionaryRef
dim valuesArrayRef as CFMutableArrayRef

myContainer = fn CFDictionaryCreateMutable( _kCFAllocatorDefault, 0,
@kCFCopyStringDictionaryKeyCallBacks, @kCFTypeDictionaryValueCallBacks )
valuesArrayRef = fn CFArrayCreateMutable( _kCFAllocatorDefault, 0,
@kCFTypeArrayCallBacks )

fn CFDictionaryAddValue( myContainer, @"values", valuesArrayRef )

end fn = myContainer





clear local
local fn AddValueToValueList( myContainer as CFMutableDictionaryRef, value
as Str255 )

dim valuesArrayRef    as CFMutableArrayRef
dim aValueStringRef   as CFStringRef

long if ( fn CFDictionaryContainsKey( myContainer, @"values" ) )
valuesArrayRef = fn CFDictionaryGetValue( myContainer, @"values" )
long if valuesArrayRef
aValueStringRef = fn CFStringCreateWithPascalString( _kCFAllocatorDefault,
value, _kCFStringEncodingUTF8 )
fn CFArrayAppendValue( valuesArrayRef, aValueStringRef )
fn CFDictionaryReplaceValue( myContainer, @"values", valuesArrayRef )
end if
end if
end fn





clear local
local fn ShowValueList( myContainer as CFMutableDictionaryRef )

dim valuesArrayRef   as CFMutableArrayRef
dim aValueStringRef  as CFStringRef
dim aStringValue     as Str255
dim valuesCount      as int
dim i                as int
dim ok               as Boolean
dim r                as Rect

long if (fn CFDictionaryContainsKey( myContainer, @"values" ) )
valuesArrayRef = fn CFDictionaryGetValue( myContainer, @"values" )
long if valuesArrayRef
valuesCount = fn CFArrayGetCount( valuesArrayRef )
long if valuesCount > 0
for i = 0 to ( valuesCount - 1 )
aValueStringRef = (CFStringRef) fn CFArrayGetValueAtIndex( valuesArrayRef,
i )
ok = fn CFStringGetPascalString( aValueStringRef, @aStringValue, 256,
_kCFStringEncodingUTF8 )
SetRect( r, 110, 10+((i+1)*32), 210, 26+((i+1)*32) )
edit field 1, aStringValue, @r, _statFramedInvert + _hilite
next i
end if
end if
end if
end fn




clear local
local fn ShowValueListCCode( myContainer as CFMutableDictionaryRef )

dim valuesArrayRef   as CFMutableArrayRef
dim aValueStringRef  as CFStringRef
dim aStringValue     as Str255
dim valuesCount      as int
dim i                as int
dim ok               as Boolean
dim r                as Rect

long if (fn CFDictionaryContainsKey( myContainer, @"values" ) )
valuesArrayRef = fn CFDictionaryGetValue( myContainer, @"values" )
long if valuesArrayRef
valuesCount = fn CFArrayGetCount( valuesArrayRef )
long if valuesCount > 0
for i = 0 to ( valuesCount - 1 )
BeginCCode

char aValue;

aValueStringRef = (CFStringRef)CFArrayGetValueAtIndex( valuesArrayRef, i_S
); 
// oK = CFStringGetCString( aValueStringRef, (void*)&aStringValue$, 256,
kCFStringEncodingUTF8 );
oK = CFStringGetCString( aValueStringRef, (void*)&aValue, 256,
kCFStringEncodingUTF8 );
SetRect( (void*)&r, 310, 10 + ((i_S + 1) * 32), 510, 26 + ((i_S + 1) * 32)
); 
FBEditField( 1, PSstrcpy( STACK_PUSH, &aValue ), (void*)&r, 13 + 16,
kFBParamMissing, 0, 0 );


EndC
next i
end if
end if
end if
end fn





dim aDictionary as CFMutableDictionaryRef
dim r           as Rect
dim wa          as WindowAttributes

wa = _kWindowCloseBoxAttribute¬
     _kWindowCollapseBoxAttribute¬
     _kWindowFullZoomAttribute¬
     _kWindowResizableAttribute¬
     _kWindowStandardHandlerAttribute

SetRect( r, 74, 71, 600, 400 )
appearance window -1,"Thomas Peters:CFDictionary", @r,
_kDocumentWindowClass, wa
window 1

aDictionary = fn CreateValueList

fn AddValueToValueList( aDictionary, "application_id" )
fn AddValueToValueList( aDictionary, "user_id" )
fn AddValueToValueList( aDictionary, "created_by" )
fn AddValueToValueList( aDictionary, "date_created" )

fn ShowValueList( aDictionary )
fn ShowValueListCCode( aDictionary )
fn CFRelease( aDictionary )

do
HandleEvents
until gFBQuit
'------------------ snip