Delphi DLL Requires Chilkat v11.7.0+
Delphi DLL
Handle QR Code Errors
See more QR Code Examples
Demonstrates what happens when a request is refused. QrCode returns false and the response holds errors[0] with three members: a code that does not change between versions, the path of the request member at fault (a JSON Pointer such as /encoding/qr/version), and a message. Requests are checked strictly, so a misspelled option is an error rather than being silently ignored. LastErrorText has the same information in more detail.Chilkat Delphi DLL Downloads
var
success: Boolean;
fmt: HCkFormats;
json: HCkJsonObject;
jsonOut: 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();
json := CkJsonObject_Create();
jsonOut := CkJsonObject_Create();
// 1. A misspelled option: "moduleSise" for "moduleSize".
CkJsonObject_UpdateString(json,'payload.text','https://www.chilkatsoft.com/');
CkJsonObject_UpdateInt(json,'render.moduleSise',8);
success := CkFormats_QrCode(fmt,'generate',json,jsonOut);
if (success = False) then
begin
Memo1.Lines.Add('code: ' + CkJsonObject__stringOf(jsonOut,'errors[0].code'));
Memo1.Lines.Add('path: ' + CkJsonObject__stringOf(jsonOut,'errors[0].path'));
Memo1.Lines.Add('message: ' + CkJsonObject__stringOf(jsonOut,'errors[0].message'));
end;
// 2. A value out of range: QR versions are 1 to 40.
CkJsonObject_Clear(json);
CkJsonObject_UpdateString(json,'payload.text','https://www.chilkatsoft.com/');
CkJsonObject_UpdateInt(json,'encoding.qr.version',41);
success := CkFormats_QrCode(fmt,'generate',json,jsonOut);
if (success = False) then
begin
Memo1.Lines.Add('code: ' + CkJsonObject__stringOf(jsonOut,'errors[0].code'));
Memo1.Lines.Add('path: ' + CkJsonObject__stringOf(jsonOut,'errors[0].path'));
Memo1.Lines.Add('message: ' + CkJsonObject__stringOf(jsonOut,'errors[0].message'));
end;
// 3. Too much data: this text does not fit a version 1 symbol.
CkJsonObject_Clear(json);
CkJsonObject_UpdateString(json,'payload.text','https://www.chilkatsoft.com/barcode_overview.asp');
CkJsonObject_UpdateInt(json,'encoding.qr.version',1);
success := CkFormats_QrCode(fmt,'generate',json,jsonOut);
if (success = False) then
begin
Memo1.Lines.Add('code: ' + CkJsonObject__stringOf(jsonOut,'errors[0].code'));
Memo1.Lines.Add('path: ' + CkJsonObject__stringOf(jsonOut,'errors[0].path'));
Memo1.Lines.Add('message: ' + CkJsonObject__stringOf(jsonOut,'errors[0].message'));
end;
// A program can act on the code.
if (CkJsonObject__stringOf(jsonOut,'errors[0].code') = 'capacityExceeded') then
begin
Memo1.Lines.Add('The text is too long for the symbol size allowed.');
end;
// Sample output:
// code: unknownOption
// path: /render/moduleSise
// message: unknown option
// code: outOfRange
// path: /encoding/qr/version
// message: the value is out of range
// code: capacityExceeded
// path: /payload
// message: the payload does not fit the requested QR version at the requested error-correction level
// The text is too long for the symbol size allowed.
CkFormats_Dispose(fmt);
CkJsonObject_Dispose(json);
CkJsonObject_Dispose(jsonOut);