[fpc-pascal] android JNI JString to String

Ludo Brands ludo.brands at free.fr
Tue Apr 26 13:58:03 CEST 2011

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
2c45. It talks about the same problem calling GetStringChars from C. The
function returns non null terminated utf16 data.

You could also go the hard way, something along the lines of:
  Chars := Env^.GetStringChars(Env, JStr, @IsCopy);
  if (Chars = nil) then begin
    Result := ''
  end else begin
    len:=Env^.GetStringLength(Env, JStr);
    Env^.ReleaseStringChars(Env, JStr, Chars);

-----Message d'origine-----
De : fpc-pascal-bounces at lists.freepascal.org
[mailto:fpc-pascal-bounces at lists.freepascal.org] De la part de herux
Envoyé : mardi 26 avril 2011 13:06
À : fpc-pascal at lists.freepascal.org
Objet : Re: RE : [fpc-pascal] android JNI JString to String

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);

and the log I retrieved :

04-26 17:53:17.942: DEBUG/proj_debug(711): e <--- only "e" character

from input AJString =

so I thought, this is not about that. but I do not know why

View this message in context:
Sent from the Free Pascal - General mailing list archive at Nabble.com.
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org

More information about the fpc-pascal mailing list