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

Generate a QR Code with the Barcode Method

See more QR Code Examples

Demonstrates the Barcode method, which is the general form of QrCode: the request names the symbology, and everything else is the same. QrCode is Barcode with the symbology already set to qr, and identical requests to the two methods give identical results. A program that will produce more than one kind of barcode can use Barcode for all of them.

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.Formats,
  Chilkat.JsonObject;

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

procedure RunDemo;
var
  success: Boolean;
  json: TJsonObject;
  fmt: TFormats;
  jsonOut: TJsonObject;
  json2: TJsonObject;

begin
  success := False;

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

  json := TJsonObject.Create;
  json.UpdateString('symbology','qr');
  json.UpdateString('payload.text','https://www.chilkatsoft.com/');
  json.UpdateString('output.path','qa_output/qr_from_barcode.png');
  json.UpdateBool('output.overwrite',True);
  json.UpdateString('output.return','none');

  fmt := TFormats.Create;
  jsonOut := TJsonObject.Create;
  success := fmt.Barcode('generate',json,jsonOut);
  if (success = False) then
    begin
      WriteLn(fmt.LastErrorText);
      Exit;
    end;

  WriteLn('symbology: ' + jsonOut.StringOf('symbols[0].symbology'));
  WriteLn('QR version: ' + jsonOut.IntOf('symbols[0].selectedEncoding.version'));
  WriteLn('image: ' + jsonOut.IntOf('outputs[0].width') + ' x ' + jsonOut.IntOf('outputs[0].height') + ' pixels');

  //  The image written to qa_output/qr_from_barcode.png:

  //  image

  //  Barcode requires the symbology.  QrCode does not.
  json2 := TJsonObject.Create;
  json2.UpdateString('payload.text','https://www.chilkatsoft.com/');
  success := fmt.Barcode('generate',json2,jsonOut);
  if (success = False) then
    begin
      WriteLn('without a symbology: ' + jsonOut.StringOf('errors[0].code') + ' at ' + jsonOut.StringOf('errors[0].path'));
    end;

  //  Sample output:

  //  symbology: qr
  //  QR version: 3
  //  image: 148 x 148 pixels
  //  without a symbology: missingOption at /symbology


  json.Free;
  fmt.Free;
  jsonOut.Free;
  json2.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.