(Delphi ActiveX) Get Contents of File as Base64
Demonstrates how to read the contents of a file and convert to a base64 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;
success: Integer;
begin
bd := TChilkatBinData.Create(Self);
success := bd.LoadFile('qa_data/jpg/starfish.jpg');
if (success = 0) then
begin
Memo1.Lines.Add('Failed to load file.');
Exit;
end;
Memo1.Lines.Add(bd.GetEncoded('base64'));
// If you want mult-line base64:
Memo1.Lines.Add('--');
Memo1.Lines.Add(bd.GetEncoded('base64_mime'));
// If you want hex..
Memo1.Lines.Add('--');
Memo1.Lines.Add(bd.GetEncoded('hex'));
// etc.
end;
|