Tcl Requires Chilkat v11.7.0+
Tcl
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 Tcl Downloads
load ./chilkat.dll
set success 0
# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set fmt [new_CkFormats]
set jsonOut [new_CkJsonObject]
set json [new_CkJsonObject]
CkJsonObject_UpdateString $json "target" "symbol"
CkJsonObject_UpdateString $json "validation.scope" "capacity"
CkJsonObject_UpdateString $json "payload.text" "https://www.chilkatsoft.com/barcode_overview.asp"
set success [CkFormats_QrCode $fmt "validate" $json $jsonOut]
if {$success == 0} then {
puts [CkFormats_lastErrorText $fmt]
delete_CkFormats $fmt
delete_CkJsonObject $jsonOut
delete_CkJsonObject $json
exit
}
puts "status: [CkJsonObject_stringOf $jsonOut validationStatus]"
set n [CkJsonObject_SizeOfArray $jsonOut "checks"]
for {set i 0} {$i <= [expr $n - 1]} {incr i} {
CkJsonObject_put_I $jsonOut $i
puts " [CkJsonObject_stringOf $jsonOut {checks[i].name}]: [CkJsonObject_stringOf $jsonOut {checks[i].status}]"
}
# 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"
set success [CkFormats_QrCode $fmt "validate" $json $jsonOut]
if {$success == 0} then {
puts [CkFormats_lastErrorText $fmt]
delete_CkFormats $fmt
delete_CkJsonObject $jsonOut
delete_CkJsonObject $json
exit
}
puts "status: [CkJsonObject_stringOf $jsonOut validationStatus]"
set n [CkJsonObject_SizeOfArray $jsonOut "checks"]
for {set i 0} {$i <= [expr $n - 1]} {incr i} {
CkJsonObject_put_I $jsonOut $i
puts " [CkJsonObject_stringOf $jsonOut {checks[i].name}]: [CkJsonObject_stringOf $jsonOut {checks[i].status}]"
}
set n [CkJsonObject_SizeOfArray $jsonOut "findings"]
for {set i 0} {$i <= [expr $n - 1]} {incr i} {
CkJsonObject_put_I $jsonOut $i
puts "finding: [CkJsonObject_stringOf $jsonOut {findings[i].code}] at [CkJsonObject_stringOf $jsonOut {findings[i].path}]"
puts " [CkJsonObject_stringOf $jsonOut {findings[i].message}]"
}
# 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
delete_CkFormats $fmt
delete_CkJsonObject $jsonOut
delete_CkJsonObject $json