Jacek Laskowski 57 Posted August 9 (edited) If the data variable contains any character outside the Latin alphabet, such as a Polish diacritical chars, the function returns nil data: AnsiString = 'ąęść'; pObj := fPyEngine.PyUnicode_FromString(PAnsiChar(data)); <-- return nil fPyModule.SetVar('data', pObj); <-- then this raises an exception How to properly pass diacritical chars in a string? ps. the function has Unicode in its name, which means it should probably allow arbitrary characters Edited August 9 by Jacek Laskowski Share this post Link to post
David Heffernan 2463 Posted August 9 (edited) Why are you expecting ANSI encodings to be of use? Why aren't you using Unicode, either UTF8 or UTF16. I believe the function you call expects UTF8 which of course you are not passing. Then again I'm not sure why you picked on this function to make a string. Edited August 9 by David Heffernan 1 Share this post Link to post
pyscripter 828 Posted August 9 P4D provides a function: function TPythonEngine.PyUnicodeFromString(const AString : UnicodeString) : PPyObject; 1 Share this post Link to post
Jacek Laskowski 57 Posted August 10 (edited) 21 hours ago, David Heffernan said: Why are you expecting ANSI encodings to be of use? Why aren't you using Unicode, either UTF8 or UTF16. I believe the function you call expects UTF8 which of course you are not passing. Then again I'm not sure why you picked on this function to make a string. I passed what the function expected: PyUnicode_FromString:function (s:PAnsiChar):PPyObject; cdecl; Anyway, unfortunately the module has no documentation, so I also rely on examples from this forum, SO and demos in my experiments. I didn't know that there is a second analogous function with an almost identical name. @pyscripter Thx I am slowly learning, admittedly, the additional difficulty is the lack of knowledge of Python, but AI helps with this. Edited August 10 by Jacek Laskowski Share this post Link to post
David Heffernan 2463 Posted August 10 3 hours ago, Jacek Laskowski said: unfortunately the module has no documentation This is a Python API function which is documented. And the documentation states UTF8. You won't see encodings other than UTF8 and UTF16 in the API. 1 Share this post Link to post