Delphi DLL Requires Chilkat v11.7.0+
Delphi DLL
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 Delphi DLL Downloads
var
success: Boolean;
fmt: HCkFormats;
json: HCkJsonObject;
jsonOut: HCkJsonObject;
levels: HCkJsonArray;
i: Integer;
json2: 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();
CkJsonObject_UpdateString(json,'payload.text','https://www.chilkatsoft.com/barcode_overview.asp');
// Encode the same text at each level.
levels := CkJsonArray_Create();
CkJsonArray_Load(levels,'["L","M","Q","H"]');
for i := 0 to 3 do
begin
CkJsonObject_UpdateString(json,'encoding.qr.errorCorrection',CkJsonArray__stringAt(levels,i));
success := CkFormats_QrCode(fmt,'generate',json,jsonOut);
if (success = False) then
begin
Memo1.Lines.Add(CkFormats__lastErrorText(fmt));
Exit;
end;
Memo1.Lines.Add('level ' + CkJsonArray__stringAt(levels,i) + ': version ' + IntToStr(CkJsonObject_IntOf(jsonOut,'symbols[0].selectedEncoding.version')) + ', '
+ IntToStr(CkJsonObject_IntOf(jsonOut,'symbols[0].dimensions.modulesWide')) + ' modules wide');
end;
// 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.
json2 := CkJsonObject_Create();
CkJsonObject_UpdateString(json2,'payload.text','https://chilkatsoft.com');
CkJsonObject_UpdateString(json2,'encoding.qr.errorCorrection','L');
success := CkFormats_QrCode(fmt,'generate',json2,jsonOut);
if (success = False) then
begin
Memo1.Lines.Add(CkFormats__lastErrorText(fmt));
Exit;
end;
Memo1.Lines.Add('level L requested: version ' + IntToStr(CkJsonObject_IntOf(jsonOut,'symbols[0].selectedEncoding.version')) + ', level ' + CkJsonObject__stringOf(jsonOut,'symbols[0].selectedEncoding.errorCorrection'));
CkJsonObject_UpdateBool(json2,'encoding.qr.boostErrorCorrection',True);
success := CkFormats_QrCode(fmt,'generate',json2,jsonOut);
if (success = False) then
begin
Memo1.Lines.Add(CkFormats__lastErrorText(fmt));
Exit;
end;
Memo1.Lines.Add('level L with boost: version ' + IntToStr(CkJsonObject_IntOf(jsonOut,'symbols[0].selectedEncoding.version')) + ', level ' + CkJsonObject__stringOf(jsonOut,'symbols[0].selectedEncoding.errorCorrection'));
// 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
CkFormats_Dispose(fmt);
CkJsonObject_Dispose(json);
CkJsonObject_Dispose(jsonOut);
CkJsonArray_Dispose(levels);
CkJsonObject_Dispose(json2);