PDA

View Full Version : const char* of C++ to String of Delphi in SDL2



kotai
25-04-2014, 02:05 PM
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:


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:


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:


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_R ENDER_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.

Andru
25-04-2014, 05:18 PM
It should be:


function SDL_GetHint( const name: PAnsiChar): PAnsiChar; cdecl; external 'SDL2.dll';

kotai
25-04-2014, 05:44 PM
The problem of PAnsiChar is I can not use width NewGen copiler (andriod and ios).

Andru
25-04-2014, 06:24 PM
Hm, strange. Did you try something like this?


var
aux : string;
auxUTF8 : UTF8string;
begin
auxUTF8 := SDL_GetHint(PChar(UTF8Encode(SDL_HINT_RENDER_SCALE _QUALITY)));
aux := auxUTF8;
end.

kotai
25-04-2014, 08:08 PM
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