Develop PDF417 with Delphi

2

Good afternoon. I use an old report generator for Delphi XE7 ( pReport ). I have the source code for it, and I've made a lot of changes to it. Now one more challenge, I need to include a new type of Barcode on the generator. It would be PDF417 . Does anyone have any idea how to do this?

From what I saw in the report generator project, it uses the Vgr_BarCode , which would be a free library but is no longer maintained. This library was made by Andreas Schmidt but at the time of generating 2D barcodes, the library was discontinued. Does anyone use this library? If so, have you evolved yet? I hope I was specific to the question.

    
asked by anonymous 13.10.2016 / 18:50

1 answer

3

Taking into account that it is enough to add the functionality of generating barcode and PDF417 format with "PDF417Lib", it follows toturial:

There is no need to install dpk that comes along unless you want to implement something at design time.

First step is to add the following directories in the project search path (Ctrl + Shift + F11):

...\pas417lib-master\vcl
...\pas417lib-master\src

Now it follows the code of the classes that implemented:

BarcodeGenerator - Interface

unit BarcodeGenerator;

interface

uses
  Graphics;

type
  IBarcodeGenerator = interface
    ['{BDBF2DC5-29CB-413F-9920-579D4213B638}']

    function GetPdf417(AValue: String): TBitmap;    
  end;

implementation

end.

BarcodeGeneratorImpl - Implementation

unit BarcodeGeneratorImpl;

interface

uses
  Graphics, PDF417Barcode, BarcodeGenerator;

type
  TBarcodeGeneratorImpl = class(TInterfacedObject, IBarcodeGenerator)

  private
    MyCodeBar: TPDF417BarcodeVCL;

  public
    constructor Create;
    destructor Destroy; override;   
    function GetPdf417(AValue: String): TBitmap;   
  end;

implementation

uses
  SysUtils;

{ THelperBarcodeGenerator }

constructor TBarcodeGeneratorImpl.Create;
begin
  MyCodeBar := TPDF417BarcodeVCL.Create(nil);
end;

destructor TBarcodeGeneratorImpl.Destroy;
begin
  FreeAndNil(MyCodeBar);
  inherited;
end;

function TBarcodeGeneratorImpl.GetPdf417(AValue: String): TBitmap;
begin
  MyCodeBar.Lines.Add(AValue);
  Result := MyCodeBar.Bitmap;
end;

end.

Now in this example, a normal unit was created, with the visual part, a TEdit, a TImage and a TButton were added.

Usage example

unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
   Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls;

type
  TForm2 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);    
  end;

var
  Form2: TForm2;

implementation

uses
  BarcodeGenerator, BarcodeGeneratorImpl;

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
var
  FBarcodeGenerator: IBarcodeGenerator;
begin    
  FBarcodeGenerator     := TBarcodeGeneratorImpl.Create;
  Image1.Picture.Bitmap := FBarcodeGenerator.GetPdf417(Edit1.Text);   
end;

end.

I think with the 2 units BarcodeGenerator and BarcodeGeneratorImpl, it's easy for you to inject this function into your framework.

    
14.10.2016 / 22:15