DataFlex Requires Chilkat v11.7.0+
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoFmt
Variant vJson
Handle hoJson
Variant vJsonOut
Handle hoJsonOut
String sTemp1
Move False To iSuccess
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatFormats)) To hoFmt
If (Not(IsComObjectCreated(hoFmt))) Begin
Send CreateComObject of hoFmt
End
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonOut
If (Not(IsComObjectCreated(hoJsonOut))) Begin
Send CreateComObject of hoJsonOut
End
// 1. A misspelled option: "moduleSise" for "moduleSize".
Get ComUpdateString Of hoJson "payload.text" "https://www.chilkatsoft.com/" To iSuccess
Get ComUpdateInt Of hoJson "render.moduleSise" 8 To iSuccess
Get pvComObject of hoJson to vJson
Get pvComObject of hoJsonOut to vJsonOut
Get ComQrCode Of hoFmt "generate" vJson vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComStringOf Of hoJsonOut "errors[0].code" To sTemp1
Showln "code: " sTemp1
Get ComStringOf Of hoJsonOut "errors[0].path" To sTemp1
Showln "path: " sTemp1
Get ComStringOf Of hoJsonOut "errors[0].message" To sTemp1
Showln "message: " sTemp1
End
// 2. A value out of range: QR versions are 1 to 40.
Send ComClear To hoJson
Get ComUpdateString Of hoJson "payload.text" "https://www.chilkatsoft.com/" To iSuccess
Get ComUpdateInt Of hoJson "encoding.qr.version" 41 To iSuccess
Get pvComObject of hoJson to vJson
Get pvComObject of hoJsonOut to vJsonOut
Get ComQrCode Of hoFmt "generate" vJson vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComStringOf Of hoJsonOut "errors[0].code" To sTemp1
Showln "code: " sTemp1
Get ComStringOf Of hoJsonOut "errors[0].path" To sTemp1
Showln "path: " sTemp1
Get ComStringOf Of hoJsonOut "errors[0].message" To sTemp1
Showln "message: " sTemp1
End
// 3. Too much data: this text does not fit a version 1 symbol.
Send ComClear To hoJson
Get ComUpdateString Of hoJson "payload.text" "https://www.chilkatsoft.com/barcode_overview.asp" To iSuccess
Get ComUpdateInt Of hoJson "encoding.qr.version" 1 To iSuccess
Get pvComObject of hoJson to vJson
Get pvComObject of hoJsonOut to vJsonOut
Get ComQrCode Of hoFmt "generate" vJson vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComStringOf Of hoJsonOut "errors[0].code" To sTemp1
Showln "code: " sTemp1
Get ComStringOf Of hoJsonOut "errors[0].path" To sTemp1
Showln "path: " sTemp1
Get ComStringOf Of hoJsonOut "errors[0].message" To sTemp1
Showln "message: " sTemp1
End
// A program can act on the code.
Get ComStringOf Of hoJsonOut "errors[0].code" To sTemp1
If (sTemp1 = "capacityExceeded") Begin
Showln "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.
End_Procedure