Reading Barcodes with Delphi using win32 dll
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 win32 DLL interface to the SDK – if you would rather use the COM interface then click here.
Download the barcode reader sdk from here
Now at this point you can either use the ready made project at the following location:
<installation folder>\Projects\Delphi using win32 dll\Project1.dpr
<installation folder>\Projects\Delphi using win32 dll\Softekbarcode.pas
…into your working folder and add it your project (right click on your project in the Project Manager and select Add and browse for the Softekbarcode.pas file)
Open your PAS file (e.g Unit1.pas) and add SoftekBarcode to the “uses” section.
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, SoftekBarcode;
Declare a variable called hBarcode of type Pointer. This will be our handle to the barcode library. You wil also need to declare some other variables for the example code below:
var hBarcode: Pointer; i: Integer; barcodeValue: String; nBarCodes: Integer;
In the procedure where you want to read the barcodes add the following code:
if (InitSoftekLibrary('\path\to\sdk\x86\softekbarcode.dll') = false) then exit; hBarcode:=mtCreateBarcodeInstance; mtSetMultipleRead(hBarcode, true); nBarCodes := mtScanBarcode(hBarcode, pAnsiChar(UTF8String('someimage.tif'))); if (nBarcodes > 0) then begin for i := 1 to nBarcodes do begin barcodeValue := System.Utf8ToUnicodeString(mtGetBarString(hBarcode, i)); end; end; mtDestroyBarcodeInstance(hBarcode);
Where \path\to\sdk\x86\softekbarcode.dll is the path to the location of the softekbarcode.dll file. Note that this might need to be the x64 version on some systems. The InitSoftekLibrary function only needs to be called once, so it would be better to place it in the FormCreate procedure.
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 email@example.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:
mtSetReadQrCode(hBarcode, true); mtSetLicenseKey(hBarcode, pAnsiChar(UTF8String('MY LICENSE KEY')));