Sample code for 30+ languages & platforms
Delphi DLL 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 Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
fmt: HCkFormats;
jsonOut: HCkJsonObject;
i: Integer;
n: Integer;
json: HCkJsonObject;

begin
success := False;

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

fmt := CkFormats_Create();
jsonOut := CkJsonObject_Create();

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

success := CkFormats_QrCode(fmt,'validate',json,jsonOut);
if (success = False) then
  begin
    Memo1.Lines.Add(CkFormats__lastErrorText(fmt));
    Exit;
  end;
Memo1.Lines.Add('status: ' + CkJsonObject__stringOf(jsonOut,'validationStatus'));
n := CkJsonObject_SizeOfArray(jsonOut,'checks');
for i := 0 to n - 1 do
  begin
    CkJsonObject_putI(jsonOut,i);
    Memo1.Lines.Add('  ' + CkJsonObject__stringOf(jsonOut,'checks[i].name') + ': ' + CkJsonObject__stringOf(jsonOut,'checks[i].status'));
  end;

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

success := CkFormats_QrCode(fmt,'validate',json,jsonOut);
if (success = False) then
  begin
    Memo1.Lines.Add(CkFormats__lastErrorText(fmt));
    Exit;
  end;
Memo1.Lines.Add('status: ' + CkJsonObject__stringOf(jsonOut,'validationStatus'));
n := CkJsonObject_SizeOfArray(jsonOut,'checks');
for i := 0 to n - 1 do
  begin
    CkJsonObject_putI(jsonOut,i);
    Memo1.Lines.Add('  ' + CkJsonObject__stringOf(jsonOut,'checks[i].name') + ': ' + CkJsonObject__stringOf(jsonOut,'checks[i].status'));
  end;

n := CkJsonObject_SizeOfArray(jsonOut,'findings');
for i := 0 to n - 1 do
  begin
    CkJsonObject_putI(jsonOut,i);
    Memo1.Lines.Add('finding: ' + CkJsonObject__stringOf(jsonOut,'findings[i].code') + ' at ' + CkJsonObject__stringOf(jsonOut,'findings[i].path'));
    Memo1.Lines.Add('  ' + CkJsonObject__stringOf(jsonOut,'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

CkFormats_Dispose(fmt);
CkJsonObject_Dispose(jsonOut);
CkJsonObject_Dispose(json);