Lazarus Pascal Requires Chilkat v11.7.0+
Lazarus Pascal
QR Code with Binary Data
See more QR Code Examples
Demonstrates a QR code that holds arbitrary bytes rather than text. The payload type is binary and the bytes are given as base64 in payload.base64. Any byte value may be used, including zero. Keep in mind that many phone camera apps expect text, so binary payloads are for readers that you control.Chilkat Lazarus Pascal Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.BinData,
Chilkat.Formats,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
bd: TBinData;
json: TJsonObject;
fmt: TFormats;
jsonOut: TJsonObject;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The bytes to encode. Here they come from hex, but they could be loaded from a file with LoadFile.
bd := TBinData.Create;
success := bd.AppendEncoded('000102030405FF00FE4368696C6B6174','hex');
if (success = False) then
begin
WriteLn(bd.LastErrorText);
Exit;
end;
json := TJsonObject.Create;
json.UpdateString('payload.type','binary');
json.UpdateString('payload.base64',bd.GetEncoded('base64'));
json.UpdateString('output.path','qa_output/qr_binary.png');
json.UpdateBool('output.overwrite',True);
json.UpdateString('output.return','none');
fmt := TFormats.Create;
jsonOut := TJsonObject.Create;
success := fmt.QrCode('generate',json,jsonOut);
if (success = False) then
begin
WriteLn(fmt.LastErrorText);
Exit;
end;
WriteLn('bytes given: ' + bd.NumBytes);
WriteLn('bytes encoded: ' + jsonOut.IntOf('symbols[0].payloadBytes'));
WriteLn('mode: ' + jsonOut.StringOf('symbols[0].selectedEncoding.mode'));
WriteLn('QR version: ' + jsonOut.IntOf('symbols[0].selectedEncoding.version'));
// The image written to qa_output/qr_binary.png:
//
// Sample output:
// bytes given: 16
// bytes encoded: 16
// mode: byte
// QR version: 2
bd.Free;
json.Free;
fmt.Free;
jsonOut.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.