Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Get Contents of File as Base64
See more Encryption Examples
Demonstrates how to read the contents of a file and convert to a base64 string.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.BinData;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
bd: TBinData;
begin
success := False;
bd := TBinData.Create;
success := bd.LoadFile('qa_data/jpg/starfish.jpg');
if (success = False) then
begin
WriteLn('Failed to load file.');
Exit;
end;
WriteLn(bd.GetEncoded('base64'));
// If you want mult-line base64:
WriteLn('--');
WriteLn(bd.GetEncoded('base64_mime'));
// If you want hex..
WriteLn('--');
WriteLn(bd.GetEncoded('hex'));
// etc..
bd.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.