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

Validate a QR Code Request

See more QR Code Examples

Demonstrates the validate operation, which examines a request without producing anything. The scope says how far to look: definition checks the options, capacity also checks that the data fits a QR symbol, and layout also checks the rendered size against the limits. The response has a validationStatus of valid or invalid, a list of checks, and findings[] describing what is wrong. A request that cannot be understood at all, such as one with a misspelled option, still makes the call fail in the usual way.

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;
  fmt: TFormats;
  jsonOut: TJsonObject;
  i: Integer;
  n: Integer;
  json: TJsonObject;

begin
  success := False;

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

  fmt := TFormats.Create;
  jsonOut := TJsonObject.Create;

  json := TJsonObject.Create;
  json.UpdateString('target','symbol');
  json.UpdateString('validation.scope','capacity');
  json.UpdateString('payload.text','https://www.chilkatsoft.com/barcode_overview.asp');

  success := fmt.QrCode('validate',json,jsonOut);
  if (success = False) then
    begin
      WriteLn(fmt.LastErrorText);
      Exit;
    end;
  WriteLn('status: ' + jsonOut.StringOf('validationStatus'));
  n := jsonOut.SizeOfArray('checks');
  for i := 0 to n - 1 do
    begin
      jsonOut.I := i;
      WriteLn('  ' + jsonOut.StringOf('checks[i].name') + ': ' + jsonOut.StringOf('checks[i].status'));
    end;

  //  The same text does not fit version 2 at error-correction level H.
  json.UpdateInt('encoding.qr.maxVersion',2);
  json.UpdateString('encoding.qr.errorCorrection','H');

  success := fmt.QrCode('validate',json,jsonOut);
  if (success = False) then
    begin
      WriteLn(fmt.LastErrorText);
      Exit;
    end;
  WriteLn('status: ' + jsonOut.StringOf('validationStatus'));
  n := jsonOut.SizeOfArray('checks');
  for i := 0 to n - 1 do
    begin
      jsonOut.I := i;
      WriteLn('  ' + jsonOut.StringOf('checks[i].name') + ': ' + jsonOut.StringOf('checks[i].status'));
    end;

  n := jsonOut.SizeOfArray('findings');
  for i := 0 to n - 1 do
    begin
      jsonOut.I := i;
      WriteLn('finding: ' + jsonOut.StringOf('findings[i].code') + ' at ' + jsonOut.StringOf('findings[i].path'));
      WriteLn('  ' + jsonOut.StringOf('findings[i].message'));
    end;

  //  Sample output:

  //  status: valid
  //    definition: passed
  //    capacity: passed
  //    layout: notApplicable
  //  status: invalid
  //    definition: passed
  //    capacity: failed
  //    layout: notApplicable
  //  finding: capacityExceeded at /payload
  //    the payload does not fit any admitted QR version at the selected error-correction level


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