title: Delphi 7 - Decode base 64 string to a file
body: <p>I am trying to find a way to decode base64 string and then save it to a file using Delphi 7 (this specific Delphi version).</p>
  
  <p>The base64 string it-self is a PDF file, encoded to base64 as part of HL7 message. Almost all examples that I found were not compatible with Delphi 7.</p>
  
  <p>Anyone can help?</p>
  
  <p><strong>UPDATE:</strong> </p>
  
  <p>As suggested by Remy Lebeau to use TidDecoderMIME.
  Is this the correct way to decode and save to binary file?</p>
  
  <p><code>
  var
      MStream:TMemoryStream;
      Decoder:TIdDecoderMIME;
      Base64: string;
  begin
      Decoder := TIdDecoderMIME.Create(nil);
      MStream := TMemoryStream.Create;
      Base64 := 'abcd1234';
      Decoder.DecodeToStream(Base64,MStream);
      MStream.SaveToFile('example.pdf');
      FreeAndNil(Decoder);
      FreeAndNil(MStream);
  end;</code></p>