title: How to use escape sequences in strings that work with both TMemo and TIdLogFile
body: <p>Using C++Builder XE6, I wrote a log file class that derives from TIdLogFile:</p>
  <pre><code>#include &lt;IdLogFile.hpp&gt;
  
  class TIdLogFileEx : public TIdLogFile
  {
      typedef TIdLogFile inherited;
  
      public:
          inline __fastcall TIdLogFileEx (TComponent* AOwner) : inherited(AOwner) {}
          inline __fastcall TIdLogFileEx () : inherited() {}
  
          virtual void __fastcall LogInfo (const System::UnicodeString AText);
  };
  
  void __fastcall TIdLogFileEx::LogInfo (const System::UnicodeString AText)
  {
      LogWriteString(_D(&quot;Info : &quot;) + AText + EOL);
  }
  </code></pre>
  <p>This works as expected for plaintext strings, but not for strings that contain escape sequences.</p>
  <p>The following code demonstrates the problem:</p>
  <pre><code>void __fastcall TForm1::Button1Click (TObject *Sender)
  {
      UnicodeString U = &quot;\x95&quot; + UnicodeString(&quot;Test&quot;) + &quot;\x85&quot;;
      AnsiString A = U;
  
      TIdLogFileEx* File = new TIdLogFileEx;
  
      try
      {
          File-&gt;Filename = &quot;Test.log&quot;;
          File-&gt;Active   = true;
  
          File-&gt;LogInfo(U);
          File-&gt;LogInfo(A);
          Memo1-&gt;Lines-&gt;Add(U);
          Memo1-&gt;Lines-&gt;Add(A);
  
          U = _D(&quot;\x95&quot;) + UnicodeString(&quot;Test&quot;) + _D(&quot;\x85&quot;);
          A = U;
  
          File-&gt;LogInfo(U);
          File-&gt;LogInfo(A);
          Memo1-&gt;Lines-&gt;Add(U);
          Memo1-&gt;Lines-&gt;Add(A);
      }
      __finally
      {
          delete File;
      }
  }
  </code></pre>
  <p>The output to Memo1 is:</p>
  <pre><code>•Test…
  •Test…
  Test        (actually &lt;U+0095&gt;Test&lt;U+0085&gt;)
  ?Test?
  </code></pre>
  <p>The log file contains:</p>
  <pre><code>Info : ?Test?
  Info : ?Test?
  Info : •Test…
  Info : ?Test?
  </code></pre>
  <p>How do I use escape sequences that work with both <code>TMemo</code> and <code>TIdLogFile</code> / <code>TIdLogFileEx</code>, and are also portable?</p>
  <p>Note that <code>_D(&quot;\x2022&quot;)</code> and <code>_D(&quot;\x2026&quot;)</code> don't work as expected when the default string type is <code>AnsiString</code>.</p>