Results 1 to 5 of 5

Thread: const char* of C++ to String of Delphi in SDL2

  1. #1

    const char* of C++ to String of Delphi in SDL2

    Hi.

    I am using SDL2 in DelphiXE5/XE6 and I have a problem with all SDL2 functions that return a string, the value I read are always Japanese letters. According to the documentation of SDL2 all string are encoded in UTF8. In fact SDL2 functions that I have to send a string I do with: PChar (UTF8Encode (string)) and it works perfectly.

    I put a concrete case: function SDL_GetHint

    Documentation of SDL:
    Code:
    Syntax
    const char* SDL_GetHint(const char* name)
    
    Function Parameters
    name : the hint to query;
     
    Return Value
    Returns the string value of a hint or NULL if the hint isn't set.
    Implementation in Delphi:
    Code:
    function SDL_GetHint( const name: PChar): PChar; cdecl; external 'SDL2.dll';
    I have tried different ways to read the value of the string but none Works:
    Code:
    var
       aux : string;
    begin
         aux := SDL_GetHint(PChar(UTF8Encode(SDL_HINT_RENDER_SCALE_QUALITY)));
         aux := PChar(SDL_GetHint(PChar(UTF8Encode(SDL_HINT_RENDER_SCALE_QUALITY))));
         aux := UTF8Decode(SDL_GetHint(PChar(UTF8Encode(SDL_HINT_RENDER_SCALE_QUALITY))));
         aux := PChar(UTF8Decode(SDL_GetHint(PChar(UTF8Encode(SDL_HINT_RENDER_SCALE_QUALITY)))));
         aux := UTF8Decode(PChar(SDL_GetHint(PChar(UTF8Encode(SDL_HINT_RENDER_SCALE_QUALITY)))));
    end;
    Any idea how to recover the real value of the string?

    Thanks.
    www.kotai.es
    www.remakesonline.com -> Nemesis Online & Bubble Bobble Online & Castlevania Online & Penguin Adventure Online
    www.miniracingonline.com

  2. #2
    It should be:
    Code:
    function SDL_GetHint( const name: PAnsiChar): PAnsiChar; cdecl; external 'SDL2.dll';

  3. #3
    The problem of PAnsiChar is I can not use width NewGen copiler (andriod and ios).
    www.kotai.es
    www.remakesonline.com -> Nemesis Online & Bubble Bobble Online & Castlevania Online & Penguin Adventure Online
    www.miniracingonline.com

  4. #4
    Hm, strange. Did you try something like this?
    Code:
    var
       aux : string;
       auxUTF8 : UTF8string;
    begin
         auxUTF8 := SDL_GetHint(PChar(UTF8Encode(SDL_HINT_RENDER_SCALE_QUALITY)));
         aux := auxUTF8;
    end.

  5. #5
    With PAnsiChar(SDL_GetHint(PChar(UTF8Encode(SDL_HINT_RE NDER_SCALE_QUALITY))));
    work OK, but with
    UTF8String(SDL_GetHint(PChar(UTF8Encode(SDL_HINT_R ENDER_SCALE_QUALITY))));
    or UTF8String(PChar(SDL_GetHint(PChar(UTF8Encode(SDL_ HINT_RENDER_SCALE_QUALITY)))));
    or PChar(UTF8String(SDL_GetHint(PChar(UTF8Encode(SDL_ HINT_RENDER_SCALE_QUALITY)))));
    not work.

    Thanks
    www.kotai.es
    www.remakesonline.com -> Nemesis Online & Bubble Bobble Online & Castlevania Online & Penguin Adventure Online
    www.miniracingonline.com

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •