[fpc-pascal] More help with unicode

Jonas Maebe jonas.maebe at elis.ugent.be
Sat Nov 10 16:30:00 CET 2007


On 10 Nov 2007, at 16:23, Felipe Monteiro de Carvalho wrote:

> Which I tryed to convert to:
>
>    if UnicodeEnabledOS then
>      SendMessage(fHandle, WM_SETTEXT, 0,
> LPARAM(PWideChar(Utf8Decode(TheText))))
>    else
>      SendMessage(fHandle, WM_SETTEXT, 0,  
> LPARAM(PChar(Utf8ToAnsi(TheText))));
>
> But this doesn't seam to work, and the text is shown scrambled.

You're making the same error which Marco pointed out earlier:  
Utf8Decode returns a (reference counted) widestring, but you are not  
assigning it to anything so it ends up in a (reusable) temp location.  
As soon as the next temporary widestring has to be created, the  
previous one is destroyed and the pwidechar will point to a random  
memory block.

The same goes for the Utf8ToAnsi() call, except that here it is an  
ansistring instead of a widestring.


Jonas



More information about the fpc-pascal mailing list