{"id":516,"date":"2012-11-23T10:54:31","date_gmt":"2012-11-23T10:54:31","guid":{"rendered":"http:\/\/www.bardecode.com\/en1\/?p=516"},"modified":"2013-03-05T11:50:08","modified_gmt":"2013-03-05T11:50:08","slug":"using-the-sdk-with-borland-delphi","status":"publish","type":"post","link":"https:\/\/www.bardecode.com\/en1\/using-the-sdk-with-borland-delphi\/","title":{"rendered":"Using the SDK with Borland Delphi"},"content":{"rendered":"<p>The following code shows how the Softek barcode Reader Toolkit can be used from Borland Delphi to\u00a0extract barcode information\u00a0from images and memory bitmaps.<\/p>\n<p><a href=\"http:\/\/www.bardecode.com\/en\/knowledge-base\/182-unicode-problems-in-delphi-2009.html\">Click here<\/a>\u00a0for some tips on using the toolkit with Delphi 2009.<\/p>\n<p><a href=\"http:\/\/bardecode.com\/downloads\/delphi_softekbarcode.zip\">Click here to download<\/a>\u00a0a Borland Delphi example in a zip file.<\/p>\n<p>The following code was kindly provided by Marian Aldenh?vel of MBA Software-Consulting.<\/p>\n<p>&nbsp;<\/p>\n<pre>\r\nunit SoftekBarCode;\r\n\r\n{ (c)2003 Marian Aldenh?vel MBA Software-Consulting\r\n     Rosenhain 23\r\n     53123 Bonn\r\n\r\n <a href=\"mailto:marian@mba-software.de\">marian@mba-software.de<\/a> \r\n\r\n  This unit dynamically imports the functions from the Softek Barcode Library.\r\n\r\n  Usage:\r\n\r\n  - Call InitLibrary from somewhere in your program before calling any of\r\n    the functions.\r\n  - See the documentation from Softek for the use of the actual functions.\r\n\r\n}\r\n\r\ninterface\r\n\r\nuses Windows,SysUtils;\r\n\r\ntype short=shortint;\r\n     long=integer;\r\n     PLong=^long;\r\n\r\nvar stGetBitmapResolution:function():integer; stdcall;\r\n    stSetBitmapResolution:function(newValue:integer):integer; stdcall;\r\n    stGetDebugTraceFile:function():PChar; stdcall;\r\n    stSetDebugTraceFile:function(lpszNewValue:PChar):PChar; stdcall;\r\n    stGetLineJump:function():integer; stdcall;\r\n    stSetLineJump:function(nNewValue:integer):integer; stdcall;\r\n    stGetLowerRatio:function():double; stdcall;\r\n    stSetLowerRatio:function(newValue:double):double; stdcall;\r\n    stGetMinOccurrence:function():short; stdcall;    \r\n    stSetMinOccurrence:function(nNewValue:short):short; stdcall;    \r\n    stGetMultipleRead:function():bool; stdcall;    \r\n    stSetMultipleRead:function(bNewValue:bool):bool; stdcall;\r\n    stGetNoiseReduction:function():short; stdcall;\r\n    stSetNoiseReduction:function(nNewValue:short):short; stdcall;    \r\n    stGetPageNo:function():short; stdcall;    \r\n    stSetPageNo:function(nNewValue:short):short; stdcall;    \r\n    stGetPrefOccurrence:function():short; stdcall;    \r\n    stSetPrefOccurrence:function(nNewValue:short):short; stdcall;    \r\n    stGetQuietZoneSize:function():short; stdcall;    \r\n    stSetQuietZoneSize:function(nNewValue:short):short; stdcall;    \r\n    stGetRotation:function():short; stdcall;    \r\n    stSetRotation:function(nNewValue:short):short; stdcall;    \r\n    stGetUpperRatio:function():double; stdcall;    \r\n    stSetUpperRatio:function(newValue:double):double; stdcall;    \r\n    stGetReadCode39:function():bool; stdcall;\r\n    stSetReadCode39:function(bNewValue:bool):bool; stdcall;\r\n    stGetReadEAN13:function():bool; stdcall;    \r\n    stSetReadEAN13:function(bNewValue:bool):bool; stdcall;    \r\n    stGetReadEAN8:function():bool; stdcall;\r\n    stSetReadEAN8:function(bNewValue:bool):bool; stdcall;    \r\n    stGetReadUPCA:function():bool; stdcall;    \r\n    stSetReadUPCA:function(bNewValue:bool):bool; stdcall;    \r\n    stGetReadUPCE:function():bool; stdcall;    \r\n    stSetReadUPCE:function(bNewValue:bool):bool; stdcall;    \r\n    stGetShowCheckDigit:function():bool; stdcall;    \r\n    stSetShowCheckDigit:function(bNewValue:bool):bool; stdcall;    \r\n    stGetReadCode128:function():bool; stdcall;    \r\n    stSetReadCode128:function(bNewValue:bool):bool; stdcall;    \r\n    stGetCode39NeedStartStop:function():bool; stdcall;    \r\n    stSetCode39NeedStartStop:function(bNewValue:bool):bool; stdcall;    \r\n    stGetReadCode25:function():bool; stdcall;    \r\n    stSetReadCode25:function(bNewValue:bool):bool; stdcall;    \r\n    stGetColorThreshold:function():short; stdcall;    \r\n    stSetColorThreshold:function(nNewValue:short):short; stdcall;    \r\n    stGetBarString:function(index:short):PChar; stdcall;    \r\n    stScanBarCode:function(FileName:PChar):short; stdcall;    \r\n    stScanBarCodeFromBitmap:function(hBitmap:long):short; stdcall;    \r\n    stGetBarStringType:function(index:short):PChar; stdcall;    \r\n    stGetBarStringPos:function(nBarCode:short;var pTopLeftX,pTopLeftY,pBotRightX,pBotRightY:Long):short; stdcall;\r\n    stSetScanRect:function(TopLeftX,TopLeftY,BottomRightX,BottomRightY:Long;MappingMode:short):bool; stdcall;\r\n    stGetReadPatchCodes:function():bool; stdcall;\r\n    stSetReadPatchCodes:function(bNewValue:bool):bool; stdcall;\r\n    stSaveBitmap:function(hBitmap:Long;strFilePath:PChar):bool; stdcall;\r\n\r\nfunction stGetErrorString(ErrorCode:short):string;\r\n\r\nprocedure InitLibrary;\r\nprocedure DoneLibrary;\r\n\r\ntype ESoftekBarCodeError=class(Exception);\r\n\r\nimplementation\r\n\r\nfunction stGetErrorString(ErrorCode:short):string;\r\nbegin\r\n  case ErrorCode of\r\n    -1:Result:='Error opening file';\r\n    -2:Result:='File is Multi Plane';\r\n    -3:Result:='Invalid number of bits per sample';\r\n    -4:Result:='Memory allocation error';\r\n    -5:Result:='Invalid TIF photometric value';\r\n    else Result:=Format('Unknown error %d',[ErrorCode]);\r\n  end;\r\nend;\r\n\r\nvar LibraryHandle:THandle=0;\r\n\r\nprocedure InitLibrary;\r\n\r\n  function DoGetProcAdress(aName:string):pointer;\r\n  begin\r\n    Result:=GetProcAddress(LibraryHandle,PChar(aName));\r\n    if Result=NIL then RaiseLastOSError;\r\n  end;\r\n\r\nbegin\r\n  if LibraryHandle&lt;&gt;0 then exit;\r\n\r\n  LibraryHandle:=LoadLibrary('SoftekBarCode.dll');\r\n  if LibraryHandle=0 then RaiseLastOSError;\r\n\r\n  @stGetBitmapResolution:=DoGetProcAdress('stGetBitmapResolution');\r\n  @stSetBitmapResolution:=DoGetProcAdress('stSetBitmapResolution');\r\n  @stGetDebugTraceFile:=DoGetProcAdress('stGetDebugTraceFile');\r\n  @stSetDebugTraceFile:=DoGetProcAdress('stSetDebugTraceFile');\r\n  @stGetLineJump:=DoGetProcAdress('stGetLineJump');\r\n  @stSetLineJump:=DoGetProcAdress('stSetLineJump');\r\n  @stGetLowerRatio:=DoGetProcAdress('stGetLowerRatio');\r\n  @stSetLowerRatio:=DoGetProcAdress('stSetLowerRatio');\r\n  @stGetMinOccurrence:=DoGetProcAdress('stGetMinOccurrence');\r\n  @stSetMinOccurrence:=DoGetProcAdress('stSetMinOccurrence');\r\n  @stGetMultipleRead:=DoGetProcAdress('stGetMultipleRead');\r\n  @stSetMultipleRead:=DoGetProcAdress('stSetMultipleRead');\r\n  @stGetNoiseReduction:=DoGetProcAdress('stGetNoiseReduction');\r\n  @stSetNoiseReduction:=DoGetProcAdress('stSetNoiseReduction');\r\n  @stGetPageNo:=DoGetProcAdress('stGetPageNo');\r\n  @stSetPageNo:=DoGetProcAdress('stSetPageNo');\r\n  @stGetPrefOccurrence:=DoGetProcAdress('stGetPrefOccurrence');\r\n  @stSetPrefOccurrence:=DoGetProcAdress('stSetPrefOccurrence');\r\n  @stGetQuietZoneSize:=DoGetProcAdress('stGetQuietZoneSize');\r\n  @stSetQuietZoneSize:=DoGetProcAdress('stSetQuietZoneSize');\r\n  @stGetRotation:=DoGetProcAdress('stGetRotation');\r\n  @stSetRotation:=DoGetProcAdress('stSetRotation');\r\n  @stGetUpperRatio:=DoGetProcAdress('stGetUpperRatio');\r\n  @stSetUpperRatio:=DoGetProcAdress('stSetUpperRatio');\r\n  @stGetReadCode39:=DoGetProcAdress('stGetReadCode39');\r\n  @stSetReadCode39:=DoGetProcAdress('stSetReadCode39');\r\n  @stGetReadEAN13:=DoGetProcAdress('stGetReadEAN13');\r\n  @stSetReadEAN13:=DoGetProcAdress('stSetReadEAN13');\r\n  @stGetReadEAN8:=DoGetProcAdress('stGetReadEAN8');\r\n  @stSetReadEAN8:=DoGetProcAdress('stSetReadEAN8');\r\n  @stGetReadUPCA:=DoGetProcAdress('stGetReadUPCA');\r\n  @stSetReadUPCA:=DoGetProcAdress('stSetReadUPCA');\r\n  @stGetReadUPCE:=DoGetProcAdress('stGetReadUPCE');\r\n  @stSetReadUPCE:=DoGetProcAdress('stSetReadUPCE');\r\n  @stGetShowCheckDigit:=DoGetProcAdress('stGetShowCheckDigit');\r\n  @stSetShowCheckDigit:=DoGetProcAdress('stSetShowCheckDigit');\r\n  @stGetReadCode128:=DoGetProcAdress('stGetReadCode128');\r\n  @stSetReadCode128:=DoGetProcAdress('stSetReadCode128');\r\n  @stGetCode39NeedStartStop:=DoGetProcAdress('stGetCode39NeedStartStop');\r\n  @stSetCode39NeedStartStop:=DoGetProcAdress('stSetCode39NeedStartStop');\r\n  @stGetReadCode25:=DoGetProcAdress('stGetReadCode25');\r\n  @stSetReadCode25:=DoGetProcAdress('stSetReadCode25');\r\n  @stGetColorThreshold:=DoGetProcAdress('stGetColorThreshold');\r\n  @stSetColorThreshold:=DoGetProcAdress('stSetColorThreshold');\r\n  @stGetBarString:=DoGetProcAdress('stGetBarString');\r\n  @stScanBarCode:=DoGetProcAdress('stScanBarCode');\r\n  @stScanBarCodeFromBitmap:=DoGetProcAdress('stScanBarCodeFromBitmap');\r\n  @stGetBarStringType:=DoGetProcAdress('stGetBarStringType');\r\n  @stGetBarStringPos:=DoGetProcAdress('stGetBarStringPos');\r\n  @stSetScanRect:=DoGetProcAdress('stSetScanRect');\r\n  @stGetReadPatchCodes:=DoGetProcAdress('stGetReadPatchCodes');\r\n  @stSetReadPatchCodes:=DoGetProcAdress('stSetReadPatchCodes');\r\n  @stSaveBitmap:=DoGetProcAdress('stSaveBitmap');\r\nend;\r\n\r\nprocedure DoneLibrary;\r\nbegin\r\n  if LibraryHandle=0 then exit;\r\n\r\n  if not FreeLibrary(LibraryHandle) then RaiseLastOSError;\r\n\r\n  stGetBitmapResolution:=NIL;\r\n  stSetBitmapResolution:=NIL;\r\n  stGetDebugTraceFile:=NIL;\r\n  stSetDebugTraceFile:=NIL;\r\n  stGetLineJump:=NIL;\r\n  stSetLineJump:=NIL;\r\n  stGetLowerRatio:=NIL;\r\n  stSetLowerRatio:=NIL;\r\n  stGetMinOccurrence:=NIL;\r\n  stSetMinOccurrence:=NIL;\r\n  stGetMultipleRead:=NIL;\r\n  stSetMultipleRead:=NIL;\r\n  stGetNoiseReduction:=NIL;\r\n  stSetNoiseReduction:=NIL;\r\n  stGetPageNo:=NIL;\r\n  stSetPageNo:=NIL;\r\n  stGetPrefOccurrence:=NIL;\r\n  stSetPrefOccurrence:=NIL;\r\n  stGetQuietZoneSize:=NIL;\r\n  stSetQuietZoneSize:=NIL;\r\n  stGetRotation:=NIL;\r\n  stSetRotation:=NIL;\r\n  stGetUpperRatio:=NIL;\r\n  stSetUpperRatio:=NIL;\r\n  stGetReadCode39:=NIL;\r\n  stSetReadCode39:=NIL;\r\n  stGetReadEAN13:=NIL;\r\n  stSetReadEAN13:=NIL;\r\n  stGetReadEAN8:=NIL;\r\n  stSetReadEAN8:=NIL;\r\n  stGetReadUPCA:=NIL;\r\n  stSetReadUPCA:=NIL;\r\n  stGetReadUPCE:=NIL;\r\n  stSetReadUPCE:=NIL;\r\n  stGetShowCheckDigit:=NIL;\r\n  stSetShowCheckDigit:=NIL;\r\n  stGetReadCode128:=NIL;\r\n  stSetReadCode128:=NIL;\r\n  stGetCode39NeedStartStop:=NIL;\r\n  stSetCode39NeedStartStop:=NIL;\r\n  stGetReadCode25:=NIL;\r\n  stSetReadCode25:=NIL;\r\n  stGetColorThreshold:=NIL;\r\n  stSetColorThreshold:=NIL;\r\n  stGetBarString:=NIL;\r\n  stScanBarCode:=NIL;\r\n  stScanBarCodeFromBitmap:=NIL;\r\n  stGetBarStringType:=NIL;\r\n  stGetBarStringPos:=NIL;\r\n  stSetScanRect:=NIL;\r\n  stGetReadPatchCodes:=NIL;\r\n  stSetReadPatchCodes:=NIL;\r\n  stSaveBitmap:=NIL;\r\nend;\r\n\r\ninitialization\r\nfinalization\r\n  DoneLibrary;\r\nend.<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The following code shows how the Softek barcode Reader Toolkit can be used from Borland Delphi to\u00a0extract barcode information\u00a0from images and memory bitmaps. Click here\u00a0for some tips on using the toolkit with Delphi 2009. Click here to download\u00a0a Borland Delphi example in a zip file. The following code was kindly provided by Marian Aldenh?vel of<\/p>\n<p><a href=\"https:\/\/www.bardecode.com\/en1\/using-the-sdk-with-borland-delphi\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":322,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,31],"tags":[19,46,47,45,48],"class_list":["post-516","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-knowledge-base","category-software-development-kits","tag-barcode","tag-borland-delphi","tag-delphi","tag-software-development-kits-2","tag-toolkit"],"_links":{"self":[{"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/posts\/516"}],"collection":[{"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/comments?post=516"}],"version-history":[{"count":2,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/posts\/516\/revisions"}],"predecessor-version":[{"id":1680,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/posts\/516\/revisions\/1680"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/media\/322"}],"wp:attachment":[{"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/media?parent=516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/categories?post=516"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/tags?post=516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}