DataFlex Requires Chilkat v11.7.0+
DataFlex
QR Code Error Correction Levels
See more QR Code Examples
Demonstrates the four QR error-correction levels. L, M, Q and H allow a reader to recover the data when about 7%, 15%, 25% and 30% of the symbol is damaged or covered. More error correction leaves less room for data, so the same text needs a larger symbol at a higher level. The default is M. The example also shows boostErrorCorrection, which raises the level for free when the chosen version has room to spare.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoFmt
Variant vJson
Handle hoJson
Variant vJsonOut
Handle hoJsonOut
Handle hoLevels
Integer i
Variant vJson2
Handle hoJson2
String sTemp1
Integer iTemp1
Integer iTemp2
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
Get ComUpdateString Of hoJson "payload.text" "https://www.chilkatsoft.com/barcode_overview.asp" To iSuccess
// Encode the same text at each level.
Get Create (RefClass(cComChilkatJsonArray)) To hoLevels
If (Not(IsComObjectCreated(hoLevels))) Begin
Send CreateComObject of hoLevels
End
Get ComLoad Of hoLevels '["L","M","Q","H"]' To iSuccess
For i From 0 To 3
Get ComStringAt Of hoLevels i To sTemp1
Get ComUpdateString Of hoJson "encoding.qr.errorCorrection" sTemp1 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 ComLastErrorText Of hoFmt To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComStringAt Of hoLevels i To sTemp1
Get ComIntOf Of hoJsonOut "symbols[0].selectedEncoding.version" To iTemp1
Get ComIntOf Of hoJsonOut "symbols[0].dimensions.modulesWide" To iTemp2
Showln "level " sTemp1 ": version " iTemp1 ", " iTemp2 " modules wide"
Loop
// The four symbols. They hold the same text, and the higher the level, the larger the symbol:
//
// A symbol often has room left over. boostErrorCorrection uses it: the level is raised
// as far as the same version allows, so the symbol is no larger but is more robust.
Get Create (RefClass(cComChilkatJsonObject)) To hoJson2
If (Not(IsComObjectCreated(hoJson2))) Begin
Send CreateComObject of hoJson2
End
Get ComUpdateString Of hoJson2 "payload.text" "https://chilkatsoft.com" To iSuccess
Get ComUpdateString Of hoJson2 "encoding.qr.errorCorrection" "L" To iSuccess
Get pvComObject of hoJson2 to vJson2
Get pvComObject of hoJsonOut to vJsonOut
Get ComQrCode Of hoFmt "generate" vJson2 vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFmt To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComIntOf Of hoJsonOut "symbols[0].selectedEncoding.version" To iTemp1
Get ComStringOf Of hoJsonOut "symbols[0].selectedEncoding.errorCorrection" To sTemp1
Showln "level L requested: version " iTemp1 ", level " sTemp1
Get ComUpdateBool Of hoJson2 "encoding.qr.boostErrorCorrection" True To iSuccess
Get pvComObject of hoJson2 to vJson2
Get pvComObject of hoJsonOut to vJsonOut
Get ComQrCode Of hoFmt "generate" vJson2 vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFmt To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComIntOf Of hoJsonOut "symbols[0].selectedEncoding.version" To iTemp1
Get ComStringOf Of hoJsonOut "symbols[0].selectedEncoding.errorCorrection" To sTemp1
Showln "level L with boost: version " iTemp1 ", level " sTemp1
// Level L, and level M reached by the boost. The two symbols are the same size:
//
// Sample output:
// level L: version 3, 29 modules wide
// level M: version 4, 33 modules wide
// level Q: version 5, 37 modules wide
// level H: version 6, 41 modules wide
// level L requested: version 2, level L
// level L with boost: version 2, level M
End_Procedure