Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Load Entire File into BinData
Demonstrates how to load an entire file into a BinData object.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,
Chilkat.FileAccess;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
fac: TFileAccess;
bd: TBinData;
maxBytesToRead: Integer;
begin
success := False;
fac := TFileAccess.Create;
success := fac.OpenForRead('qa_data/pdf/sample.pdf');
if (success = False) then
begin
WriteLn(fac.LastErrorText);
Exit;
end;
bd := TBinData.Create;
maxBytesToRead := 99999999;
success := fac.FileReadBd(maxBytesToRead,bd);
if (success = False) then
begin
WriteLn(fac.LastErrorText);
Exit;
end;
fac.FileClose();
// The bd object contains the file data...
success := bd.WriteFile('qa_output/sample.pdf');
fac.Free;
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.