title: How to convert UTF-8 string to PChar in Delphi 2009
body: <p>I receive a string, which is displayed as <code>'{'#0'S'#0'a'#0'm'#0'p'#0'l'#0'e'#0'-'#0'M'#0'e'#0's'#0's'#0'a'#0'g'#0'e'#0'}'#0</code> in the debugger.</p>
  
  <p>I need to print it out in the debug output (<code>OutputDebugString</code>).</p>
  
  <p>When I run <code>OutputDebugString(PChar(mymsg))</code>, only the first character of the received string is displayed (probably because of the <code>#0</code> end-of-string marker).</p>
  
  <p>How can I convert that string into something <code>OutputDebugString</code> can work with?</p>
  
  <p><strong>Update 1:</strong> Here's the code. I want to print the contents of the variable <code>RxBufStr</code>.</p>
  
  <pre><code>procedure ReceivingThread.OnExecute(AContext : TIdContext);
  var
    RxBufStr: String;
  begin    
    with AContext.Connection.IOHandler do
    begin
      CheckForDataOnSource(10);
      if not InputBufferIsEmpty then
      begin
        RxBufStr := InputBuffer.Extract();
      end;
    end;
  end;
  </code></pre>