Wednesday, April 25, 2012

Convert to Base64 using TIdEncodeMIME when upgrading the compiler


As useful task for data streaming, we need to encode some parts of our database records to Base64 encoding format. For example, to save pictures in text base databases (such as XML), we do need to convert it to Base64 text format.
In Borland Developer Studio 2006, you can use Encode(String) method of the TIdEncodeMIME class to convert binary information into Base64 format. When upgrading to a newer version of C++Builder (or Delphi), for example Embarcadero RAD Studio XE2, you must use a newer method, EncodeStream(TStream *) instead of the Encode(String). In the new TIdEncoderMIME class, convering binary data using Encode method may cause unexpected error.

//In this example the Data->Picture is of type TMemoryStream
TIdEncoderMIME *Encoder = new TIdEncoderMIME(NULL);
ReturnValue += Encoder->EncodeStream(Data->Picture); //instead of Encode method
delete Encoder;



No comments:

Post a Comment