Delphi ActiveX Requires Chilkat v11.7.0+
Delphi ActiveX
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 ActiveX Downloads
var
success: Integer;
sbCard: TChilkatStringBuilder;
json: TChilkatJsonObject;
fmt: TChilkatFormats;
jsonOut: TChilkatJsonObject;
begin
success := 0;
// 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 := TChilkatStringBuilder.Create(Self);
sbCard.AppendLine('BEGIN:VCARD',1);
sbCard.AppendLine('VERSION:3.0',1);
sbCard.AppendLine('N:Smith;Alex;;;',1);
sbCard.AppendLine('FN:Alex Smith',1);
sbCard.AppendLine('ORG:Example Company',1);
sbCard.AppendLine('TITLE:Sales Manager',1);
sbCard.AppendLine('TEL;TYPE=CELL:+1-555-0100',1);
sbCard.AppendLine('EMAIL:alex.smith@example.com',1);
sbCard.AppendLine('URL:https://www.example.com',1);
sbCard.AppendLine('END:VCARD',1);
json := TChilkatJsonObject.Create(Self);
json.UpdateSb('payload.text',sbCard.ControlInterface);
json.UpdateInt('render.moduleSize',6);
json.UpdateString('output.path','qa_output/qr_vcard.png');
json.UpdateBool('output.overwrite',1);
json.UpdateString('output.return','none');
fmt := TChilkatFormats.Create(Self);
jsonOut := TChilkatJsonObject.Create(Self);
success := fmt.QrCode('generate',json.ControlInterface,jsonOut.ControlInterface);
if (success = 0) then
begin
Memo1.Lines.Add(fmt.LastErrorText);
Exit;
end;
Memo1.Lines.Add('vCard length: ' + IntToStr(sbCard.Length));
Memo1.Lines.Add('QR version: ' + IntToStr(jsonOut.IntOf('symbols[0].selectedEncoding.version')));
Memo1.Lines.Add('modules: ' + IntToStr(jsonOut.IntOf('symbols[0].dimensions.modulesWide')) + ' x ' + IntToStr(jsonOut.IntOf('symbols[0].dimensions.modulesHigh')));
Memo1.Lines.Add('image: ' + IntToStr(jsonOut.IntOf('outputs[0].width')) + ' x ' + IntToStr(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