On Nov 10, 2007 4:30 PM, Jonas Maebe <[EMAIL PROTECTED]> wrote: > 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.
Ummm, but there is nothing else on that function, so I don't see how can the temporary string be destroyed before I call SETTEXT, unless SETTEXT expects that I give it a storage that is at all times available... procedure TWin32MemoStrings.SetText(TheText: PChar); begin SendMessage(fHandle, WM_SETTEXT, 0, LPARAM(TheText)); end; Which I currently converted into (but still doesn't work): procedure TWin32MemoStrings.SetText(TheText: PChar); var AnsiBuffer: ansistring; WideBuffer: widestring; begin {$ifdef WindowsUnicodeSupport} if UnicodeEnabledOS then begin WideBuffer := Utf8Decode(TheText); SendMessage(fHandle, WM_SETTEXT, 0, LPARAM(PWideChar(WideBuffer))); end else begin AnsiBuffer := Utf8ToAnsi(TheText); SendMessage(fHandle, WM_SETTEXT, 0, LPARAM(PChar(AnsiBuffer))); end; {$else} SendMessage(fHandle, WM_SETTEXT, 0, LPARAM(TheText)); {$endif} end; Alternatively I moved AnsiBuffer and WideBuffer to the class declaration, so they are always available, which also didn't solve the problem of showing wrong characters. It shows the string ééé as if it was Ã(c)Ã(c)Ã(c) Which is what I would expect if I use ansi routines to show a utf-8 string. thanks, -- Felipe Monteiro de Carvalho _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal