Delphi DLL Requires Chilkat v11.7.0+
Delphi DLL
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 Delphi DLL Downloads
var
success: Boolean;
sbCard: HCkStringBuilder;
json: HCkJsonObject;
fmt: HCkFormats;
jsonOut: HCkJsonObject;
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 := CkStringBuilder_Create();
CkStringBuilder_AppendLine(sbCard,'BEGIN:VCARD',True);
CkStringBuilder_AppendLine(sbCard,'VERSION:3.0',True);
CkStringBuilder_AppendLine(sbCard,'N:Smith;Alex;;;',True);
CkStringBuilder_AppendLine(sbCard,'FN:Alex Smith',True);
CkStringBuilder_AppendLine(sbCard,'ORG:Example Company',True);
CkStringBuilder_AppendLine(sbCard,'TITLE:Sales Manager',True);
CkStringBuilder_AppendLine(sbCard,'TEL;TYPE=CELL:+1-555-0100',True);
CkStringBuilder_AppendLine(sbCard,'EMAIL:alex.smith@example.com',True);
CkStringBuilder_AppendLine(sbCard,'URL:https://www.example.com',True);
CkStringBuilder_AppendLine(sbCard,'END:VCARD',True);
json := CkJsonObject_Create();
CkJsonObject_UpdateSb(json,'payload.text',sbCard);
CkJsonObject_UpdateInt(json,'render.moduleSize',6);
CkJsonObject_UpdateString(json,'output.path','qa_output/qr_vcard.png');
CkJsonObject_UpdateBool(json,'output.overwrite',True);
CkJsonObject_UpdateString(json,'output.return','none');
fmt := CkFormats_Create();
jsonOut := CkJsonObject_Create();
success := CkFormats_QrCode(fmt,'generate',json,jsonOut);
if (success = False) then
begin
Memo1.Lines.Add(CkFormats__lastErrorText(fmt));
Exit;
end;
Memo1.Lines.Add('vCard length: ' + IntToStr(CkStringBuilder_getLength(sbCard)));
Memo1.Lines.Add('QR version: ' + IntToStr(CkJsonObject_IntOf(jsonOut,'symbols[0].selectedEncoding.version')));
Memo1.Lines.Add('modules: ' + IntToStr(CkJsonObject_IntOf(jsonOut,'symbols[0].dimensions.modulesWide')) + ' x ' + IntToStr(CkJsonObject_IntOf(jsonOut,'symbols[0].dimensions.modulesHigh')));
Memo1.Lines.Add('image: ' + IntToStr(CkJsonObject_IntOf(jsonOut,'outputs[0].width')) + ' x ' + IntToStr(CkJsonObject_IntOf(jsonOut,'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
CkStringBuilder_Dispose(sbCard);
CkJsonObject_Dispose(json);
CkFormats_Dispose(fmt);
CkJsonObject_Dispose(jsonOut);