Sample code for 30+ languages & platforms
Lazarus Pascal Requires Chilkat v11.0.0+

Create Password Protected Zip containing a Single File.

See more Zip Examples

Create a password-protected .zip containing a single file. (This uses the older Zip 2.0 encryption scheme, which is weaker and not as secure as AES encryption, which Chilkat Zip also supports.)

Chilkat Lazarus Pascal Downloads

Lazarus Pascal
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.Zip;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  zip: TZip;
  saveExtraPath: Boolean;

begin
  success := False;

  //  This example requires the Chilkat API to have been previously unlocked.
  //  See Global Unlock Sample for sample code.

  zip := TZip.Create;

  success := zip.NewZip('test.zip');
  if (success = False) then
    begin
      WriteLn(zip.LastErrorText);
      Exit;
    end;

  zip.SetPassword('secret');
  zip.PasswordProtect := True;

  saveExtraPath := False;
  success := zip.AddFile('/temp/hamlet.xml',saveExtraPath);

  success := zip.WriteZipAndClose();
  if (success = False) then
    begin
      WriteLn(zip.LastErrorText);
      Exit;
    end;

  WriteLn('Zip Created!');


  zip.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.