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