<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 10 Nov 2007, at 16:41, Felipe Monteiro de Carvalho wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Monaco; font-size: 10px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; ">On Nov 10, 2007 4:30 PM, Jonas Maebe <<a href="mailto:jonas.maebe@elis.ugent.be">jonas.maebe@elis.ugent.be</a>> wrote:<br><blockquote type="cite">You're making the same error which Marco pointed out earlier:<br></blockquote><blockquote type="cite">Utf8Decode returns a (reference counted) widestring, but you are not<br></blockquote><blockquote type="cite">assigning it to anything so it ends up in a (reusable) temp location.<br></blockquote><blockquote type="cite">As soon as the next temporary widestring has to be created, the<br></blockquote><blockquote type="cite">previous one is destroyed and the pwidechar will point to a random<br></blockquote><blockquote type="cite">memory block.<br></blockquote><br>Ummm, but there is nothing else on that function, so I don't see how<br>can the temporary string be destroyed before I call SETTEXT,</span></blockquote><div><br class="webkit-block-placeholder"></div><div>You should never make assumptions about when compiler-managed types are destroyed when you don't hold an explicit reference to them anymore (it may happen immediately, or a long time in the future, and anywhere in between).</div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Monaco; font-size: 10px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; ">unless<br>SETTEXT expects that I give it a storage that is at all times<br>available...<br><br>procedure TWin32MemoStrings.SetText(TheText: PChar);<br>begin<br> SendMessage(fHandle, WM_SETTEXT, 0, LPARAM(TheText));<br>end;<br><br>Which I currently converted into (but still doesn't work):<br><br>procedure TWin32MemoStrings.SetText(TheText: PChar);<br>var<br> AnsiBuffer: ansistring;<br> WideBuffer: widestring;<br>begin<br> {$ifdef WindowsUnicodeSupport}<br> if UnicodeEnabledOS then<br> begin<br> WideBuffer := Utf8Decode(TheText);<br> SendMessage(fHandle, WM_SETTEXT, 0, LPARAM(PWideChar(WideBuffer)));<br> end<br> else<br> begin<br> AnsiBuffer := Utf8ToAnsi(TheText);<br> SendMessage(fHandle, WM_SETTEXT, 0, LPARAM(PChar(AnsiBuffer)));<br> end;<br> {$else}<br> SendMessage(fHandle, WM_SETTEXT, 0, LPARAM(TheText));<br> {$endif}<br>end;<br><br>Alternatively I moved AnsiBuffer and WideBuffer to the class<br>declaration, so they are always available, which also didn't solve the<br>problem of showing wrong characters.<br><br>It shows the string ééé as if it was Ã(c)Ã(c)Ã(c)<br><br>Which is what I would expect if I use ansi routines to show a utf-8 string.<br></span></blockquote></div><br><div>The above code looks correct as far as managing the data is concerned. I don't know anything about the win32 api though, so I can't help further.</div><div><br class="webkit-block-placeholder"></div><div><br class="webkit-block-placeholder"></div><div>Jonas</div></body></html>