Lazarus Pascal Requires Chilkat v11.7.0+
Lazarus Pascal
Create a vCard (Contact) QR Code
See more QR Code Examples
Demonstrates a QR code that adds a contact to a phone when scanned. The text is a vCard, the standard format for contact details: lines between BEGIN:VCARD and END:VCARD, each ending with CRLF. A vCard is fairly long, so the symbol is larger than one holding a web address. Leave out the fields that are not needed to keep it small.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.StringBuilder,
Chilkat.Formats,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
sbCard: TStringBuilder;
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 second argument of AppendLine is cktrue to end each line with CRLF.
sbCard := TStringBuilder.Create;
sbCard.AppendLine('BEGIN:VCARD',True);
sbCard.AppendLine('VERSION:3.0',True);
sbCard.AppendLine('N:Smith;Alex;;;',True);
sbCard.AppendLine('FN:Alex Smith',True);
sbCard.AppendLine('ORG:Example Company',True);
sbCard.AppendLine('TITLE:Sales Manager',True);
sbCard.AppendLine('TEL;TYPE=CELL:+1-555-0100',True);
sbCard.AppendLine('EMAIL:alex.smith@example.com',True);
sbCard.AppendLine('URL:https://www.example.com',True);
sbCard.AppendLine('END:VCARD',True);
json := TJsonObject.Create;
json.UpdateSb('payload.text',sbCard);
json.UpdateInt('render.moduleSize',6);
json.UpdateString('output.path','qa_output/qr_vcard.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('vCard length: ' + sbCard.Length);
WriteLn('QR version: ' + jsonOut.IntOf('symbols[0].selectedEncoding.version'));
WriteLn('modules: ' + jsonOut.IntOf('symbols[0].dimensions.modulesWide') + ' x ' + jsonOut.IntOf('symbols[0].dimensions.modulesHigh'));
WriteLn('image: ' + jsonOut.IntOf('outputs[0].width') + ' x ' + jsonOut.IntOf('outputs[0].height') + ' pixels');
// The image written to qa_output/qr_vcard.png:
//
// Sample output:
// vCard length: 197
// QR version: 10
// modules: 57 x 57
// image: 390 x 390 pixels
sbCard.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.