[fpc-pascal] android JNI JString to String

2011-04-26 Thread herux
I have a strange problem, I pass data from the android String via JNI. pass data from FreePascal wideString successfully using the following code NewString: function (Env: PJNIEnv; const Unicode: PJChar; Len: JSize): JString; cdecl; GetStringChars:function(Env:PJNIEnv;Str:JString;IsCopy:PJBoolean

RE : [fpc-pascal] android JNI JString to String

2011-04-26 Thread Ludo Brands
PJChar is defined as a pointer to a word. Casting to WideString isn't working since internally Widestring has extra bytes for reference count and string length. These extra bytes are locate before the actual string. This explains why assigning Pointer(WStr) to PJChar works. Try Result := WideStrin

Re: RE : [fpc-pascal] android JNI JString to String

2011-04-26 Thread herux
thanks for the response. I am doing what you suggest. but it's still the same. I debug this line of code using android log Chars := Env^.GetStringChars(Env, AJString, nil); __android_log_write(ANDROID_LOG_DEBUG,'proj_debug',PChar(Chars)); and the log I retrieved : 04-26 17:53:17.942: DEBUG/pr

Re: RE : [fpc-pascal] android JNI JString to String

2011-04-26 Thread Jonas Maebe
On 26 Apr 2011, at 13:06, herux wrote: I debug this line of code using android log Chars := Env^.GetStringChars(Env, AJString, nil); __android_log_write(ANDROID_LOG_DEBUG,'proj_debug',PChar(Chars)); and the log I retrieved : 04-26 17:53:17.942: DEBUG/proj_debug(711): e <--- only "e" characte

RE : RE : [fpc-pascal] android JNI JString to String

2011-04-26 Thread Ludo Brands
Pchar(Chars) interpretes your widechars as chars. The widechar e is converted to the chars e and #0. The #0 is end of line for a pchar. So your debug output is as expected. Take a look at http://groups.google.com/group/android-ndk/browse_thread/thread/e0ab7aefb398 2c45. It talks about the same pr

Re: RE : RE : [fpc-pascal] android JNI JString to String

2011-04-26 Thread herux
Yes, there's bug. thanks you. I using GetStringUTFChars function JNI_JStringToString(Env: PJNIEnv; JStr: jstring): String; var IsCopy: Pjboolean; Chars: PChar; begin if JStr = nil then begin Result := ''; Exit; end; Chars:= Env^.GetStringUTFChars(Env, JStr, IsCopy); if Char