(Delphi ActiveX) Base64 Encode/Decode a String
Delphi ActiveX example to base-64 encode and decode a string.
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Chilkat_TLB;
...
procedure TForm1.Button1Click(Sender: TObject);
var
bd: TChilkatBinData;
s: WideString;
success: Integer;
strBase64: WideString;
bd2: TChilkatBinData;
decoded: WideString;
begin
bd := TChilkatBinData.Create(Self);
s := 'A friend called me up the other day and talked about investing in a dot-com that sells lobsters. Internet lobsters. Where will this end? --Donald Trump';
success := bd.AppendString(s,'utf-8');
strBase64 := bd.GetEncoded('base64');
Memo1.Lines.Add(strBase64);
// To decode:
bd2 := TChilkatBinData.Create(Self);
bd2.AppendEncoded(strBase64,'base64');
decoded := bd2.GetString('utf-8');
Memo1.Lines.Add(decoded);
end;
|