Recent

Author Topic: Accentuated characters are mutilated ?  (Read 3395 times)

KlausGunther

  • New Member
  • *
  • Posts: 36
Accentuated characters are mutilated ?
« on: January 05, 2013, 02:07:22 am »
On Windows, I have the following function to recover the text from a control, using its handle:
Code: [Select]
function MyFunction(hnd: pointer):istring; stdcall; export;
var
    len : integer;
    text : string;
begin
    len := SendMessage(hnd, WM_GETTEXTLENGTH, 0, 0); // get the total text length
    SetLength(text, len); // fixe la longueur pour text
    SendMessage(hnd, WM_GETTEXT, len + 1, LParam(PChar(text)));  / get the text itself
    result := text;
end;       

Now, I'm in France, and my texts contain french accentuated characters. And in LAzarus, the WM_GETTEXT message returns a modified text where all accentuated characters are replaced by reverse question marks. But exactly the same code works correctly in Delphi.

So, the interception of french characters is obviously done by Lazarus. How can I tell Lazarus to let the french accentuated characters as teh are ? I'm using only 8 bit Ascii character set, no Unicode whatsoever.  There must be a quite obvious thing I have overseen !

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Accentuated characters are mutilated ?
« Reply #1 on: January 05, 2013, 02:20:06 am »
I'm using only 8 bit Ascii character set, no Unicode whatsoever.
You could tell more details about that.

Lazarus uses UTF by default. I'm not entirely sure if it's {$H+} at beginning of each unit that does that, but could be. You can also try passing the string through UTF conversion functions. Some are UTF8ToSys(), SysToUTF8(), AnsiToUTF8(), UTF8ToAnsi()...

KlausGunther

  • New Member
  • *
  • Posts: 36
Re: Accentuated characters are mutilated ?
« Reply #2 on: January 05, 2013, 11:48:24 am »
Thank you very much !

I did some googleing about Lazarus and Unicode. I don't say I'm already understanding all this, but I found the solution to my problem: I use AnsiToUTF8() to convert the string returned by the API and I can work with it.

So: problem solved, and lots of new aspects to think about.