Reading Barcodes with Delphi using com
Using the Softek Barcode Reader SDK with Delphi is pretty straight forward and we include a full example project with our download. This page aims to get you up and running in less than 15 minutes…
Note that this example uses the COM interface to the SDK. If you would rather use the win32 DLL interface then click here.
Step 1.
Download the barcode reader sdk from here
Step 2.
Navigate to where the sdk was installed and open the x86 folder, right click on REGISTER.BAT and select “Run as Administrator”. This will run regsvr32 on SoftekATL.dll – which is the dll you will be using later on.
Step 3.
Open Delphi and start a new forms project or open the one you want to use for barcode reading.
Click on Component followed by Import Component to start the “Import Component Wizard”…
Click on Next to “Import a Type Library”
Scroll down to and click on “SoftekATL X.X.X Type Library”
Then click through the rest of the wizard taking the defaults.
Step 4.
Open your PAS file (e.g Unit1.pas) and add SoftekATL_TLB to the “uses” section.
e.g:
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, SoftekATL_TLB;
Step 5:
Declare a variable called oBarcode of type CBarcode and some other variables for the example code below:
var oBarcode: CBarcode; i: Integer; barcodeValue: String; nBarCodes: Integer;
Step 6:
In the procedure where you want to read the barcodes add the following code:
oBarcode := CoCBarcode.Create; oBarcode.MultipleRead := 1; oBarcode.ScanBarcode('someimage.tif'); nBarCodes := oBarcode.BarCodeCount; if (nBarcodes > 0) then begin for i := 1 to nBarcodes do begin barcodeValue := oBarcode.BarString[i]; end; end;
Step 7:
That’s it – all done. But don’t forget that there is a lot more to the sdk than just this. If you have any questions then please contactsupport@bardecode.com .
You also might wish to add some extra lines of code to turn on or off various barcode types and maybe set a license key:
oBarcode.ReadQrCode := 1; oBarcode.LicenseKey := 'MY LICENSE KEY';