Recent

Author Topic: QR Generator  (Read 1147 times)

Raf20076

  • Full Member
  • ***
  • Posts: 173
    • https://github.com/Raf20076
QR Generator
« on: January 10, 2024, 03:02:41 pm »
Hi
I Have found that lazbarcodes is broken and doesn't compile on my 2.0.6 Lazarus IDE, so
I checked the forum and found some solutions but not enought, so I used some informatiom
here and wrote QR generator using unit called qrencode_nogui from here
https://forum.lazarus.freepascal.org/index.php?topic=41519.0

But it was with no gui. I wrote example program with gui.

I hope so that could be help for anyone.


wp

  • Hero Member
  • *****
  • Posts: 11916
Re: QR Generator
« Reply #1 on: January 10, 2024, 04:34:12 pm »
I Have found that lazbarcodes is broken and doesn't compile on my 2.0.6 Lazarus IDE
I don't have 2.0.6 any more, but I checked on 2.0.8 (Windows 11, 32-bit IDE), and it is working correctly (except for the main demo which is choking on the combobox TextHint - but this should be fixed in SVN now). So, what it the error in your case?

zim

  • New Member
  • *
  • Posts: 17
Re: QR Generator
« Reply #2 on: January 10, 2024, 04:39:24 pm »
zxing ?

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: QR Generator
« Reply #3 on: January 10, 2024, 04:54:26 pm »
I tend to generate the barcode first, then LoadFromStream.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Raf20076

  • Full Member
  • ***
  • Posts: 173
    • https://github.com/Raf20076
Re: QR Generator
« Reply #4 on: January 10, 2024, 05:44:31 pm »
Hi

I used onlinemanager to install lazbarcodes 1.0.3 and opened attached example qrcodegen
It gives me errors
main.pas(87,10) Error: identifier idents no member "SaveToEpsFile"
main.pas(113,10) Error: identifier idents no member "SaveToSvgFile"
main.pas(162,10) Error: identifier idents no member "SaveToFile"

I use old Windows 7 32bit

Code: Pascal  [Select][+][-]
  1. unit main;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
  9.   ComCtrls, LCLIntf,
  10.   fpimage, fpWriteGIF,
  11.   ubarcodes;
  12.  
  13. type
  14.   TMyGifImage = class(TGifImage)
  15.   protected
  16.     class function GetWriterClass: TFPCustomImageWriterClass; override;
  17.   end;
  18.  
  19.   { TMainForm }
  20.  
  21.   TMainForm = class(TForm)
  22.     btnCreateQR: TButton;
  23.     btnSaveAsGIF: TButton;
  24.     btnSaveAsBMP: TButton;
  25.     btnSaveAsSVG: TButton;
  26.     btnSaveAsPNG: TButton;
  27.     btnSaveAsJPEG: TButton;
  28.     btnSaveAsEPS: TButton;
  29.     edText: TEdit;
  30.     Label1: TLabel;
  31.     StatusBar: TStatusBar;
  32.     procedure btnCreateQRClick(Sender: TObject);
  33.     procedure btnSaveAsEPSClick(Sender: TObject);
  34.     procedure btnSaveAsGIFClick(Sender: TObject);
  35.     procedure btnSaveAsBMPClick(Sender: TObject);
  36.     procedure btnSaveAsPNGClick(Sender: TObject);
  37.     procedure btnSaveAsSVGClick(Sender: TObject);
  38.     procedure edTextChange(Sender: TObject);
  39.     procedure FormActivate(Sender: TObject);
  40.     procedure FormDestroy(Sender: TObject);
  41.   private
  42.     QRCode: TBarcodeQR;
  43.     procedure EnableButtons(Enable: Boolean);
  44.     procedure SaveQRCodeToImage(AFileName: String; AImageClass: TFPImageBitmapClass);
  45.  
  46.   public
  47.  
  48.   end;
  49.  
  50. var
  51.   MainForm: TMainForm;
  52.  
  53. implementation
  54.  
  55. {$R *.lfm}
  56.  
  57. class function TMyGifImage.GetWriterClass: TFPCustomImageWriterClass;
  58. begin
  59.   Result := TFPWriterGIF;
  60. end;
  61.  
  62. { TMainForm }
  63.  
  64. procedure TMainForm.btnCreateQRClick(Sender: TObject);
  65. begin
  66.   QRCode.Free;
  67.   QRCode := TBarcodeQR.Create(self);
  68.   QRCode.Text := edText.Text;
  69.   QRCode.Top := btnCreateQR.Top;
  70.   QRCode.Left := btnCreateQR.Left + btnCreateQR.Width + 10;
  71.   QRCode.Width := 168;
  72.   QRCode.Height := 168;
  73.   QRCode.Generate;
  74.   QRCode.Parent := self;
  75.  
  76.   EnableButtons(true);
  77.   StatusBar.simpleText := 'QRCode generated.';
  78. end;
  79.  
  80. procedure TMainForm.btnSaveAsEPSClick(Sender: TObject);
  81. var
  82.   fn: String;
  83. begin
  84.   if QRCode = nil then
  85.     exit;
  86.   fn := 'qrcode.eps';
  87.   QRCode.SaveToEpsFile(fn);
  88.   StatusBar.SimpleText := 'QRCode saved to "' + fn + '".';
  89. end;
  90.  
  91. procedure TMainForm.btnSaveAsGIFClick(Sender: TObject);
  92. begin
  93.   SaveQRCodeToImage('qrcode', TMyGifImage);
  94. end;
  95.  
  96. procedure TMainForm.btnSaveAsBMPClick(Sender: TObject);
  97. begin
  98.   SaveQRCodeToImage('qrcode', TBitmap);
  99. end;
  100.  
  101. procedure TMainForm.btnSaveAsPNGClick(Sender: TObject);
  102. begin
  103.   SaveQRCodeToImage('qrcode', TPortableNetworkGraphic);
  104. end;
  105.  
  106. procedure TMainForm.btnSaveAsSVGClick(Sender: TObject);
  107. var
  108.   fn: String;
  109. begin
  110.   if QRCode = nil then
  111.     exit;
  112.   fn := 'qrcode.svg';
  113.   QRCode.SaveToSvgFile(fn);
  114.   StatusBar.SimpleText := 'QRCode saved to "' + fn + '".';
  115. end;
  116.  
  117. procedure TMainForm.edTextChange(Sender: TObject);
  118. begin
  119.   EnableButtons(false);
  120. end;
  121.  
  122. procedure TMainForm.FormActivate(Sender: TObject);
  123. begin
  124.   ClientHeight := btnSaveAsEPS.Top + btnSaveAsEPS.Height + StatusBar.Height + 16;
  125. end;
  126.  
  127. procedure TMainForm.EnableButtons(Enable: Boolean);
  128. begin
  129.   btnSaveAsGIF.Visible := Enable;
  130.   btnSaveAsBMP.Visible := Enable;
  131.   btnSaveAsPNG.Visible := Enable;
  132.   btnSaveAsJPEG.Visible := Enable;
  133.   btnSaveAsSVG.Visible := Enable;
  134.   btnSaveAsEPS.Visible := Enable;
  135.   if not Enable then StatusBar.SimpleText := '';
  136. end;
  137.  
  138. procedure TMainForm.FormDestroy(Sender: TObject);
  139. begin
  140.   QRCode.Free;
  141. end;
  142.  
  143. procedure TMainForm.SaveQRCodeToImage(AFileName: String; AImageClass: TFPImageBitmapClass);
  144. var
  145.   ext: String;
  146. begin
  147.   if QRCode = nil then
  148.     exit;
  149.  
  150.   if AImageClass = TBitmap then
  151.     ext := '.bmp'
  152.   else if AImageClass = TMyGifImage then
  153.     ext := '.gif'
  154.   else if AImageClass = TPortableNetworkGraphic then
  155.     ext := '.png'
  156.   else if AImageClass = TJpegImage then
  157.     ext := '.jpg'
  158.   else
  159.     raise Exception.Create('Image format not supported.');
  160.  
  161.   AFileName := ChangeFileExt(AFileName, ext);
  162.   QRCode.SaveToFile(AFileName, AImageClass);
  163.  
  164.   StatusBar.SimpleText := 'QRCode saved to "' + AFileName + '".';
  165. end;
  166.  
  167. initialization
  168.   TPicture.RegisterFileFormat('.gif', 'gif', TMyGifImage);
  169. end.
  170.  
  171.  
« Last Edit: January 10, 2024, 05:48:44 pm by Raf20076 »

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: QR Generator
« Reply #5 on: January 10, 2024, 06:01:31 pm »
I used onlinemanager to install lazbarcodes 1.0.3 ...
How can this be? OPM provides v2.0.2 of LazBarCodes... Update the LazBarcodes installation from OPM and it should work.

Raf20076

  • Full Member
  • ***
  • Posts: 173
    • https://github.com/Raf20076
Re: QR Generator
« Reply #6 on: January 10, 2024, 06:25:17 pm »
OK

In Online Package Manger I have see picture

I messed something it seems to me that before I installed lazbars from lazarus-ccr-svn-r7320.

New version cannot be installed on Lazarus 2.0.6
« Last Edit: January 10, 2024, 06:33:28 pm by Raf20076 »

Raf20076

  • Full Member
  • ***
  • Posts: 173
    • https://github.com/Raf20076
Re: QR Generator
« Reply #7 on: January 10, 2024, 06:35:01 pm »
New version cannot be installed on Lazarus 2.0.6 at least from online manager.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: QR Generator
« Reply #8 on: January 10, 2024, 07:25:02 pm »
As I said, I don't have the early versions of the Laz v2.0.x series any more. But the OPM version compiles with 2.0.8, and it even compiles with 1.8.4. So, I don't see a reason why it should not work with 2.0.6.

Did you try a clean rebuild of the IDE? Maybe some compiles files are not updated since you obviously had the newer development version from svn in your system before. Do this: "Tools" > "Configure Build Lazarus" > in the "Clean up" box check "Clean all" and "Switch after building to automatically". Theck click "Build". It may take a while, until the IDE restarts. It should work. If if does not, tell me the error message.

Raf20076

  • Full Member
  • ***
  • Posts: 173
    • https://github.com/Raf20076
Re: QR Generator
« Reply #9 on: January 11, 2024, 07:43:42 am »
I will not risk. I have lots of components and if something goes wrong it will take time to install them again. When I move to Windows 11 and Linux (64bit) I update everything including Lazarus.

Anyway Thanks for your advise.


wp

  • Hero Member
  • *****
  • Posts: 11916
Re: QR Generator
« Reply #10 on: January 11, 2024, 01:25:44 pm »
Now you confuse me: in the other thread you write that you want to "install" many components. In Lazarus, component installation is identical to rebuilding the IDE. With every package that you install there is the risk that something may go wrong - not just with the LazBarCodes... But did you know that the IDE always makes a backup copy of itself before building itself (lazarus.old.exe)? If the new IDE does not start or work properly, delete "lazarus.exe" and rename "lazarus.old.exe" back to "lazarus.exe" to get back to the state before you attempted to install that new package.

Raf20076

  • Full Member
  • ***
  • Posts: 173
    • https://github.com/Raf20076
Re: QR Generator
« Reply #11 on: January 11, 2024, 01:51:08 pm »
I have two laptops both Windows 7 32bit. On one I have Lazarus 2.0.6 on secend Lazarus 2.2.6. On 2.0.6 I have barcodes and also lots of components But I don't want to risk because on
Lazarus 2.2.6 I got no memory left, because I installed too  many components. I will try with optimization

OS? 32/64bit?

At which point of the compilation does that error happen?

Normally every package is compiled on its own, that should not cause memory issues. Not even if you have hundreds of them.

BUT, at the very end, all needs to be linked together. That is where memory can get short (and on 32 bit systems can run out of mem).
Most compiler options will not impact this. (The -g- is useful though for compilation and linking)
However "smart linking" -XX does make it worse. If you smart link, then you easily need ten times more memory.

So make sure that smart linking is not enabled.
When you rebuild the IDE, make also sure that whatever project is open does not require smart linking. Not sure, but I think there are cases were that can conflict (or not, really not sure).

Not tested, but you may be able to explicitly disable it by specifying
 -XX- 

While it should not impact, you can also disable "smart linkable" -CX-


If the error happens before linking, then provide more details.
Which unit?
And try to use less optimization -O-1


If the error happens at runtime, i.e., when you start the ready build IDE, then avoid options like -gh
(And if you did build your own fpc, then hopefully you did not build your fpc with -gh)
« Last Edit: January 11, 2024, 01:58:30 pm by Raf20076 »

 

TinyPortal © 2005-2018