### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: QR LazReport  (Read 3500 times)

#### eldonfsr

• Sr. Member
• Posts: 285
##### QR LazReport
« on: January 24, 2022, 03:09:01 am »
Hi i follow samples show here on forum how to print QR with lazreport, but don't show me still the picture on report blank...
Code: Pascal  [Select][+][-]
1. procedure TFormCtrlHist.BtnPdfClick(Sender: TObject);
2. begin
4.   BarCodeQR1.Visible := true;
5.   frReport1.ShowReport;
6.   BarCodeQR1.Visible := false;
7. end;
8.
9. procedure TFormCtrlHist.frReport1EnterRect(Memo: TStringList; View: TfrView);
10.  var
11.   tmp : TBitmap;
12.   w,h : integer;
13.   r : TRect;
14. begin
15.   if (View.Name='Picture1')  then
16.   begin
17.     // Fields[0] --> Author
20. //     showmessage(frDBDataSet1.DataSet.Fields[5].AsString);
22.     BarCodeQR1.Update;
23.     w := BarCodeQR1.Width;
24.     h:= BarCodeQR1.Height;
25.     r:= Rect(0,0,w,h);
26.     tmp:=TBitmap.Create;
27.     tmp.Width:=w;
28.     tmp.Height:=h;
29.     // copy the qrcode bitmap  in the picture Picture1
30.     tmp.Canvas.CopyRect(r, BarCodeQR1.Canvas, r);
31.     TFrPictureView(View).Picture.Bitmap.Assign(tmp);
32.     tmp.free;
33.   end;
34. end;
35.
36.

#### dseligo

• Hero Member
• Posts: 580
##### Re: QR LazReport
« Reply #1 on: January 24, 2022, 03:31:48 am »
This works for me (QRcode2Bitmap returns bitmap):
Code: Pascal  [Select][+][-]
1. function QRkod2report(frRep: TfrReport; sKontrola, sTekst: String; iVelicinaModula, iOkvir:Integer): Boolean;
2. var frQR: TfrObject;
3.     Bmp: TBitmap;
4. begin
5.   Result := False;
6.   Bmp := QRcode2Bitmap(sTekst, iVelicinaModula, iOkvir);
7.   try
8.     frQR := frRep.FindObject(sKontrola);
9.     If frQR = nil then Exit;
10.     If not (frQR is TfrPictureView) then Exit;
11.
12.     (frQR as TfrPictureView).dx := Bmp.Width;
13.     (frQR as TfrPictureView).dy := Bmp.Height;
14.     (frQR as TfrPictureView).Picture.Bitmap := Bmp;
15.   finally
16.     Bmp.Free;
17.   end;
18.   Result := True;
19. end;

#### dseligo

• Hero Member
• Posts: 580
##### Re: QR LazReport
« Reply #2 on: January 24, 2022, 03:35:32 am »
I call this function when preparing report, somewhere above ShowReport.

#### eldonfsr

• Sr. Member
• Posts: 285
##### Re: QR LazReport
« Reply #3 on: January 24, 2022, 05:25:36 pm »
Ok i lite confuse  of parameters can you tell me what each one please...

#### dseligo

• Hero Member
• Posts: 580
##### Re: QR LazReport
« Reply #4 on: January 24, 2022, 07:35:03 pm »
sKontrola - Control name of picture field in LazReport
sTekst - text to be encoded in QR code
iVelicinaModula - QR code module size (e.g. how many pixels is one square)
iOkvir - QR code frame size

#### dseligo

• Hero Member
• Posts: 580
##### Re: QR LazReport
« Reply #5 on: January 24, 2022, 07:55:39 pm »
With this I put generated QR code on screen to test if it is correct:
Code: Pascal  [Select][+][-]
1. var Bmp: TBitmap;
2. begin
3.   Bmp := QRcode2Bitmap(edQRcode.Text, StrToInt(edSirinaModula.Text), StrToInt(edMarginaLijevo.Text));
4.   try
5.     Image1.Canvas.Clear;
6.     Image1.Width := Bmp.Width;
7.     Image1.Height := Bmp.Height;
8.     Image1.Picture.Bitmap := Bmp;
9.   finally
10.     Bmp.Free;
11.   end;
12. end;

#### eldonfsr

• Sr. Member
• Posts: 285
##### Re: QR LazReport
« Reply #6 on: January 27, 2022, 02:20:54 am »
Ok Thanks Friend..

#### eldonfsr

• Sr. Member
• Posts: 285
##### Re: QR LazReport
« Reply #7 on: February 08, 2022, 06:15:11 am »
Hi sorry you i can't find this function QRcode2Bitmap(frRep: TfrReport; sKontrola, sTekst: String; iVelicinaModula, iOkvir:Integer)
you made that or is in some package or unit...

thanks...

#### dseligo

• Hero Member
• Posts: 580
##### Re: QR LazReport
« Reply #8 on: February 09, 2022, 05:49:35 am »
Hi sorry you i can't find this function QRcode2Bitmap(frRep: TfrReport; sKontrola, sTekst: String; iVelicinaModula, iOkvir:Integer)
you made that or is in some package or unit...

I didn't give you rest of my code because in the first post you showed code that creates bitmap, so I sent you only the code which I use to check QR code on screen.

For creating QR code I use 'lazbarcodes' from Online Package Manager and here is rest of the code:
Code: Pascal  [Select][+][-]
1. uses
2.   ..., zint, lbc_qr, lbc_basic, ...
3.
4. ...
5.
6. implementation
7.
8. var QRsimbol: PointerTo_zint_symbol;
9.
10. procedure KreirajQRsimbol(sTekst:String);
11. begin
12.   if Assigned(QRsimbol) then begin
13.     ZBarcode_Delete(QRsimbol);
14.     QRsimbol := nil;
15.   end;
16.
17.   if Length(sTekst) > 0 then begin
18.     QRsimbol := ZBarcode_Create();
19.     with QRsimbol^ do begin
20.       border_width := 4;
21.       option_1 := 1; // LEVEL_L
22.     end;
23.
24.     ErrorCode := qr_code(QRsimbol, @sTekst[1], Length(sTekst));
25.     if ErrorCode <> 0 then
26.       Raise Exception.Create(QRsimbol^.errtxt);
27.   end else
28.     Raise Exception.Create('Prazni tekst za kreiranje QR simbola.');
29. end;
30.
31. procedure OslobodiQRsimbol;
32. begin
33.   ZBarcode_Delete(QRsimbol);
34.   QRsimbol := nil;
35. end;
36.
37. function GetQRsimbolBit(x, y: Integer):Boolean;
38. var iBajt, iBit: Integer;
39. begin
40.   // nađem u kojem je bajtu i bitu u bajtu GetQRsimbolBit koji tražim
41.   iBajt := x div 7; // koristi samo sedam bitova/pixela po bajtu
42.   iBit := x mod 7;
43.   Result := (QRsimbol^.encoded_data[y][iBajt] and (1 shl iBit)) <> 0;
44. end;
45.
46. // funkcija za bitmapu
47. function QRcode2Bitmap(sTekst:String; iVelicinaModula, iOkvir:Integer):TBitmap;
48. var iX,iY:Integer;
49. begin
50.   KreirajQRsimbol(sTekst); // napravi kod
51.
52.   try
53.     Result := TBitmap.Create;
54.     Result.Height := QRsimbol^.rows * iVelicinaModula + 2 * iOkvir;
55.     Result.Width := QRsimbol^.width * iVelicinaModula + 2 * iOkvir;
56.
57.     Result.Canvas.Pen.Color := clWhite;
58.     Result.Canvas.Brush.Color := clWhite;
59.     Result.Canvas.Rectangle(0, 0, Result.Width, Result.Height);
60.
61.     Result.Canvas.Brush.Color := clBlack;
62.
63.     // crtam točku po točku, mada bi vjerojatno mogao učinkovitije riješiti
64.     For iY := 0 to QRsimbol^.rows do
65.       For iX := 0 to QRsimbol^.width do
66.         If GetQRsimbolBit(iX, iY) then
67.           Result.Canvas.FillRect(iX * iVelicinaModula + iOkvir,
68.                                  iY * iVelicinaModula + iOkvir,
69.                                  iX * iVelicinaModula + iVelicinaModula + iOkvir + 1,
70.                                  iY * iVelicinaModula + iVelicinaModula + iOkvir + 1); // zadnji red i kolona nisu uključeni pa zato +1
71.   finally
72.     OslobodiQRsimbol;
73.   end;
74. end;

#### eldonfsr

• Sr. Member
• Posts: 285
##### Re: QR LazReport
« Reply #9 on: February 09, 2022, 09:27:58 pm »
Ok thanks, Yes i was working on that....