Recent

Author Topic: [SOLVED] QRCode component  (Read 2492 times)

Pe3s

  • Hero Member
  • *****
  • Posts: 574
[SOLVED] QRCode component
« on: September 23, 2023, 07:42:30 am »
Hello forum members, I have a question: are there any other components than LazBarcodes with more options?
« Last Edit: September 24, 2023, 11:59:56 am by Pe3s »

wp

  • Hero Member
  • *****
  • Posts: 12476
Re: QRCode component
« Reply #1 on: September 23, 2023, 11:48:17 am »
Be more specific. What in particular is missing?

Pe3s

  • Hero Member
  • *****
  • Posts: 574
Re: QRCode component
« Reply #2 on: September 23, 2023, 01:18:45 pm »
@wp, I can't make a business card in LazBarcode unless I don't know how to do it

wp

  • Hero Member
  • *****
  • Posts: 12476
Re: QRCode component
« Reply #3 on: September 23, 2023, 05:04:05 pm »
You mean you want to add a QRcode to a business card file for printing? You better use the barcode component in LazReport, because it saves you some steps.

But the effort to do this without LazReport is not so big. Just some scaling to correct for the differences in resolutions. As for the barcode, there is a method PaintToCanvas which allows you to draw the barcode directly on the canvas of the printer.

See attached demo which prints a business card in multiple copies from the screen to a sheet of paper.

Pe3s

  • Hero Member
  • *****
  • Posts: 574
Re: QRCode component
« Reply #4 on: September 23, 2023, 05:08:24 pm »
@wp, I meant a business card in the form of a qrcode
- First name Last Name
-address
-Phone number

wp

  • Hero Member
  • *****
  • Posts: 12476
Re: QRCode component
« Reply #5 on: September 23, 2023, 05:24:59 pm »
That's what's in the sample project. The QRCode on the business code contains the information in the other fields. Just assign the text to the text property of the barcode:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   BarcodeQR1.Text :=
  4.     'Donald Duck' + LineEnding +
  5.     '1234 Main Street, Duck Town' +  LineEnding +
  6.     'phone: +12 / 34 56 78 90' + LineEnding +
  7.     'mail: donald.duck@duckmail.org';
  8. end;

Pe3s

  • Hero Member
  • *****
  • Posts: 574
Re: QRCode component
« Reply #6 on: September 23, 2023, 07:32:14 pm »
Is it possible to set the Contact mode so that, for example, the phone can save contacts?

wp

  • Hero Member
  • *****
  • Posts: 12476
Re: QRCode component
« Reply #7 on: September 23, 2023, 11:14:33 pm »
I don't know what you mean. LazBarcode is just for displaying barcodes...

Fibonacci

  • Hero Member
  • *****
  • Posts: 615
  • Internal Error Hunter
Re: QRCode component
« Reply #8 on: September 23, 2023, 11:51:07 pm »
For low level QR code you can look here: (@wp helped me with this)
https://forum.lazarus.freepascal.org/index.php/topic,64635

What you are looking for is just vCard. QRCode contains just text/binary data, vCard format looks like this:
Code: Pascal  [Select][+][-]
  1.  BEGIN:VCARD
  2.  VERSION:4.0
  3.  FN:Simon Perreault
  4.  N:Perreault;Simon;;;ing. jr,M.Sc.
  5.  BDAY:--0203
  6.  GENDER:M
  7.  EMAIL;TYPE=work:simon.perreault@viagenie.ca
  8.  END:VCARD

So I passed this vCard to QRCode generator like this:
Code: Pascal  [Select][+][-]
  1.   TEXT_STRING := ''
  2.     +'BEGIN:VCARD'                                 +LineEnding
  3.     +'VERSION:4.0'                                 +LineEnding
  4.     +'FN:Simon Perreault'                          +LineEnding
  5.     +'N:Perreault;Simon;;;ing. jr,M.Sc.'           +LineEnding
  6.     +'BDAY:--0203'                                 +LineEnding
  7.     +'GENDER:M'                                    +LineEnding
  8.     +'EMAIL;TYPE=work:simon.perreault@viagenie.ca' +LineEnding
  9.     +'END:VCARD'                                   +LineEnding
  10.     ;

And the result you can see in the attachment

More info about vCard format:
https://en.wikipedia.org/wiki/VCard

BTW. You can still scan the QR in the attachment, despite not the best quality and small size, and it works :)
« Last Edit: September 24, 2023, 12:06:59 am by Fibonacci »

Pe3s

  • Hero Member
  • *****
  • Posts: 574
Re: QRCode component
« Reply #9 on: September 24, 2023, 11:59:42 am »
@wp, @Fibonacci, Thank you for your help, big beer :)


Pe3s

  • Hero Member
  • *****
  • Posts: 574
Re: [SOLVED] QRCode component
« Reply #10 on: September 25, 2023, 09:43:39 pm »
One more question why vcard does not show the memo contents in the next lines, only in the first one.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.    BarcodeQR1.Text := ''
  4.     +'BEGIN:VCARD'               +LineEnding
  5.     +'VERSION:3.0'               +LineEnding
  6.     +'N:'     +Edit1.Text        +LineEnding
  7.     +'ORG:'   +Edit2.Text        +LineEnding
  8.     +'ADR:'   +Edit3.Text        +LineEnding
  9.     +'TEL:'   +Edit4.Text        +LineEnding
  10.     +'EMAIL:' +Edit5.Text        +LineEnding
  11.     +'NOTE:'  +Memo1.Lines.Text  +LineEnding
  12.     +'END:VCARD';
  13. end;        
  14.  


Fibonacci

  • Hero Member
  • *****
  • Posts: 615
  • Internal Error Hunter
Re: [SOLVED] QRCode component
« Reply #11 on: September 25, 2023, 09:50:58 pm »
Sorry I'm on the phone now so I can't test, but, put another memo on your form and set it's text property to text property of this qrcode component, then you will see what vCard you generated. It's probably invalid.

Pe3s

  • Hero Member
  • *****
  • Posts: 574
Re: [SOLVED] QRCode component
« Reply #12 on: September 25, 2023, 10:01:08 pm »
qrcode only generates the first line in the memo, if we add subsequent lines to the memo it does not

wp

  • Hero Member
  • *****
  • Posts: 12476
Re: [SOLVED] QRCode component
« Reply #13 on: September 25, 2023, 10:55:30 pm »
qrcode only generates the first line in the memo, if we add subsequent lines to the memo it does not
IIRC you must replace the lineendings in the memo by '\n'
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.    BarcodeQR1.Text := ''
  4.     +'BEGIN:VCARD'               +LineEnding
  5.     +'VERSION:3.0'               +LineEnding
  6.     +'N:'     +Edit1.Text        +LineEnding
  7.     +'ORG:'   +Edit2.Text        +LineEnding
  8.     +'ADR:'   +Edit3.Text        +LineEnding
  9.     +'TEL:'   +Edit4.Text        +LineEnding
  10.     +'EMAIL:' +Edit5.Text        +LineEnding
  11.     +'NOTE:'  +StringReplace(Memo1.Lines.Text, LineEnding, '\n', [rfReplaceAll])  +LineEnding
  12.     +'END:VCARD';
  13. end;

Fibonacci

  • Hero Member
  • *****
  • Posts: 615
  • Internal Error Hunter
Re: [SOLVED] QRCode component
« Reply #14 on: September 26, 2023, 10:18:23 am »
Yes, I was trying to force him to see it himself :)

Each line in the vCard must begin with a known keyword, field type

Code: C  [Select][+][-]
  1. BEGIN:VCARD
  2. VERSION:3.0
  3. NOTE:Line 1\nLine 2\nLine 3
  4. END:VCARD

He probably had something like this:

Code: C  [Select][+][-]
  1. BEGIN:VCARD
  2. VERSION:3.0
  3. NOTE:Line 1
  4. Line 2                       # invalid
  5. Line 3                       # invalid
  6. END:VCARD

 

TinyPortal © 2005-2018