Pages

Tuesday 11 March 2014

Encoding and Decoding a String in Delphi XE4 using Indy 10

Encoding and Decoding a String in Delphi XE4 using Indy 10

I am using Delphi XE4 and Indy 10. I want to share how I encoded and decoded a file in Delphi XE4 using Indy 10 client. Include IdCoder, IdCoder3to4, IdCoderMIME units and use TIdEncoderMIME and TIdDecoderMIME classes for this purpose. Following are two simple Delphi functions which illustrate the way of encoding and decoding a file in Delphi XE4 in very simple way. 

uses

IdCoder, IdCoder3to4, IdCoderMIME;

//Encoding function in Delphi XE4

procedure TMyForm.EncodeMIME_Example;
var
  EncodeMIME: TIdEncoderMIME;
  myEncryptedFile: WideString;
  stringToBeEncoded: WideString;
begin
  EncodeMIME :=  TIdEncoderMIME.Create(Self);
  try
    myEncryptedFile := EncodeMIME.Encode(stringToBeEncoded);
  finally
    EncodeMIME.Free;
  end;
end

//Decoding function in Delphi XE4

procedure TMyForm.DecodeMIME_Example;
var
  DecodeMIME: TIdDecoderMIME;
  myDecryptedFile: WideString;
  stringToBeDecoded: WideString;
begin
  DecodeMIME :=  TIdDecoderMIME.Create(Self);
  try
    myDecryptedFile := DecodeMIME.Decode(stringToBeDecoded);
  finally
    DecodeMIME.Free;
  end;
end

No comments:

Post a Comment

About the Author

I have more than 10 years of experience in IT industry. Linkedin Profile

I am currently messing up with neural networks in deep learning. I am learning Python, TensorFlow and Keras.

Author: I am an author of a book on deep learning.

Quiz: I run an online quiz on machine learning and deep learning.