<p dir="ltr">Why are you using a TStringlist at all?</p>
<p dir="ltr">If you&#39;re encoding to Base64, encoding to UTF8 is meaningless.</p>
<p dir="ltr">Todd</p>
<div class="gmail_extra"><br><div class="gmail_quote">On 9 Aug 2016 5:54 p.m., &quot;Peter Ingham&quot; &lt;<a href="mailto:ping_delphilist@3days.co.nz" target="_blank">ping_delphilist@3days.co.nz</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    <p>If you look at the output file in a hex editor, what do you see?</p>
    <p>If the first 3 bytes are <code>0xEF,0xBB,0xBF, then that is a
        &quot;Byte Order Mark&quot;.</code></p>
    <p><code>UTF-8 is a method for encoding UNICODE characters using
        8-Bit Bytes.</code></p>
    <p><code>A file containing 7-Bit ASCII (high-order bit of every
        character zero), when converted to UTF-8 is likely to look</code><code></code>
      very similar.  For anything else, all bets are off.   Treating
      them as universally equivalent is asking for trouble.<br>
    </p>
    <p>Many text editors will look for Byte Order marks (of varying
      types) and use them without displaying them (e.g: see
      <a href="https://en.wikipedia.org/wiki/Byte_order_mark#UTF-8" target="_blank">https://en.wikipedia.org/wiki/<wbr>Byte_order_mark#UTF-8</a>).</p>
    <p><br>
    </p>
    <p>Regards<br>
    </p>
    <div>On 9/08/2016 5:01 p.m., Robert Martin
      wrote:<br>
    </div>
    <blockquote type="cite">
      <pre>Hi guys


I have been struggling to get some basic Mime encoding working, I have 
the following code which I use to Mime64 Encode a picture contained in a 
TImage component....

             Base64 := TMime64.create;
             try
                     MemoryStream := TMemoryStream.Create;
                     MemoryStream.Position := 0;
Image.Picture.Graphic.<wbr>SaveToStream(MemoryStream);

                     ReportImage.ImageMime   := 
Base64.Encode_New(<wbr>MemoryStream);
             .....

Function shown below...



function TMime64.Encode_New(<wbr>aSourceStream: TMemoryStream): String;
var
     IdEncoderMIME       : TIdEncoderMIME;
     Sl                  : TStringList;
begin
     Result := &#39;&#39;;
     try

         IdEncoderMIME := TIdEncoderMIME.Create(nil);
         sl := TStringList.Create;
         try
             aSourceStream.Position := 0;
             Result := IdEncoderMIME.EncodeStream(<wbr>aSourceStream);

             sl.Text := Result;
             sl.SaveToFile(&#39;d:\d\a.txt&#39;, TEncoding.UTF8);
         finally
             IdEncoderMIME.Free;
             sl.Free;
         end;
     except
         on E : Exception do begin
             raise EMimeError.Create(E.Message);
         end;
     end;
end;

The issue is that when I try to save the results in a UTF8 formatted 
file (the destination is to be a UTF-8 formatted XML file), there are 
&#39;bad&#39; characters in the file which are invisible in Notepad++ but are 
present.

If I save without specifying the file encoding ( 
sl.SaveToFile(&#39;d:\d\a.txt&#39;) instead of sl.SaveToFile(&#39;d:\d\a.txt&#39;, 
TEncoding.UTF8)   ) I have what appears to be a clean ASCII file. My 
understanding is that ASCII characters have the same byte value (0-127) 
in an ASCII formatted file or a UTF-8 formatted file so I don&#39;t 
understand why the values would change.

Any suggestions.


p.s. I have to be able to save the file as UTF-8 because that is what 
the destination XML is encoded in.  Currently it is &#39;corrupt&#39; because of 
the &#39;bad&#39; characters.

p.p.s TIdEncoderMIME.EncodeStream returns a String.  I am using Delphi Xe2.

p.p.p.s I know it is something stupid I am doing !




Thanks
Rob


______________________________<wbr>_________________
NZ Borland Developers Group - Delphi mailing list
Post: <a href="mailto:delphi@listserver.123.net.nz" target="_blank">delphi@listserver.123.net.nz</a>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/<wbr>listinfo/delphi</a>
Unsubscribe: send an email to <a href="mailto:delphi-request@listserver.123.net.nz" target="_blank">delphi-request@listserver.123.<wbr>net.nz</a> with Subject: unsubscribe

</pre>
    </blockquote>
    <br>
  </div>

<br>______________________________<wbr>_________________<br>
NZ Borland Developers Group - Delphi mailing list<br>
Post: <a href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" rel="noreferrer" target="_blank">http://delphi.org.nz/mailman/<wbr>listinfo/delphi</a><br>
Unsubscribe: send an email to <a href="mailto:delphi-request@listserver.123.net.nz">delphi-request@listserver.123.<wbr>net.nz</a> with Subject: unsubscribe<br></blockquote></div></div>