Two lines of code to add QR, UPC, EAN code scanning in iOS Delphi applications

Friday, December 20, 2013

For an internal project, we looked at integrating QR code scanning in an iOS application. As we didn't feel like reinventing the wheel and deal with the complexities of deciphering a QR code, we searched for existing code and after trying out several solutions, found ZBar to be one of the most solid libraries. The project is at : http://zbar.sourceforge.net/

After doing this evaluation in XCode with ObjectiveC, the next duty was to find out how we could use an ObjectiveC library from a Delphi FireMonkey project. There are several important details to pay attention to when doing this, but finally this also proved to work and in the typical Delphi RAD philosophy, we decided to create a wrapper Delphi component for this. With this wrapper component, scanning a QR, UPC or EAN code from Delphi is as simple as two lines of code:

procedure TForm1136.Button1Click(Sender: TObject);
begin
  // line1: activate the code scanner. This shows the camera that should be aimed at the QR or UPC code
  TMSFMXZBarReader1.Show;
end;

procedure TForm1136.TMSFMXZBarReader1GetResult(Sender: TObject;
  AResult: string);
begin
  //line 2: the OnGetResult event is triggered when the code was retrieved and this returns it as a text
  ListBox1.Items.Insert(0, AResult);
end;
You can download the sample project and the package with full source code to install the TTMSFMXZBarReader component here: http://www.tmssoftware.net/public/TMSFMXZBarReader.zip
Open the package file TMSFMXZBarReaderPkgDXE*.dproj from Delphi XE* (* = 5,6,7,8) and compile & install this package. This will add the component TTMSFMXZBarReader on the tool palette. Then you can drop this component in an iOS Delphi appplication and start using it in 1,2, 3 ...

   

Bruno Fierens


Bookmarks: 

This blog post has received 26 comments.


1. Monday, December 30, 2013 at 5:59:47 AM

This works brilliantly, it was up and running on an iPhone 5s in minutes! So much better than having to install zing and call an intenet. Would it be too much to ask to extend it to Android?

I am sure like me others would not mind paying for this. I have seen a number of requests.

Regards Mike




Price Michael


2. Friday, January 03, 2014 at 4:49:44 AM

Nice work,

If you can extend this to Android I would pay for this.

van Dijk Bart


3. Saturday, January 04, 2014 at 11:12:49 AM

Very nice. Works great!

re:Android
Yes, we need an Android version. :)

Brian Long has a solution that works well but it''s not an elegant solution and there are lots of challenges to get it to work in an app. A component set would be much more productive.

Bob



Lawrence Robert


4. Tuesday, January 07, 2014 at 4:45:48 AM

hello,
great example !!

I tested the example on my Iphone 5 ... works fine but:

the camera is slow to make a focus .. it''s normal ?

I have touched the display, but does not focus the image.. why ?

thanks!

Antonello


5. Tuesday, January 07, 2014 at 2:17:06 PM

Our Delphi class is a wrapper around the ZBar scanner component you can find at: http://zbar.sourceforge.net/
Our wrapper component is not responsible for focus control. You might direct your question at the developers of the ZBar class itself.

Bruno Fierens


6. Thursday, January 16, 2014 at 1:40:45 PM

Bruno

Are we persuading you to consider the Android version :)

Will be watching the webinar on programing devices next Wednesday. With your wrapper skills do you think this may be an area TMS could address

Regards Mike

Price Michael


7. Friday, January 17, 2014 at 5:19:22 AM

Correct, it is under investigation.

Bruno Fierens


8. Monday, January 20, 2014 at 2:20:26 PM

Android Version Please :-)

Ferono


9. Sunday, February 02, 2014 at 10:20:32 PM

excellent!
re android, check out
http://john.whitham.me.uk/xe5/

as maybe a starting point for an android component
(this uses zbar as well)
:)
Brian


Hamilton Brian


10. Sunday, February 09, 2014 at 6:10:48 AM


>Android Version Please :-)

Your wish is grandet. ;-)

http://www.file-upload.net/download-8601754/TKRBarCodeSanner.zip.html

For the iOS part "my code" is using the TMS component, so this works for Android and iOS as well.

Thomas K


11. Tuesday, February 11, 2014 at 9:50:52 PM

works great Thomas, thanks !!

Hamilton Brian


12. Sunday, February 16, 2014 at 4:16:10 AM

Thomas
Installed your component and compiled the example all went well (after I copied FMX.TKRBarCodeScanner.pas into the sample directory. but clicking the scan button crashes the phone.
I am testing on Galaxy S4, any suggestions.

Thanks Mike

Price Michael


13. Tuesday, February 18, 2014 at 3:23:08 AM

Thomas
Found the problem the solution requires the installation of zxing as well. Was really after the same elegant solution Bruno had done for IOS

Price Michael


14. Wednesday, May 28, 2014 at 10:33:15 PM

Thanks for sharing. But I am testing another EAN barcode SDK these days. Anyone knows that?
http://www.keepautomation.com/products/excel_barcode/barcodes/ean_13.html

babard


15. Monday, January 05, 2015 at 12:32:01 PM

Hi
This component installs and compiles into XE8 isoS 32
great
but not for iOS64 bit
error is
[DCC Error] E2597 ld: missing required architecture arm64 in file ZBarSDK\libzbar.a (3 slices) for architecture arm64

i.e the zbar library looks like its missing 64 bit compiled versions of the files?

Hamilton Brian


16. Thursday, June 25, 2015 at 12:25:09 PM

Hamilton
Could you sent me your working your working Application. Always get the message of "current platform is not supported". No problem with install and compile....
I am using XE8

Hamilton


17. Thursday, June 25, 2015 at 2:31:52 PM

An update has been released with XE8 packages.
This component is iOS 32 bit only as the ZBar lib is iOS 32 only.


Nancy Lescouhier


18. Friday, July 24, 2015 at 3:19:19 PM

Hi,
I try to install TMSFMXZBarReaderPkgDXE8.dproj package in EX8 update 1 but I don''t be able to install.
I tried with IOS32, IOS64 and Simulator but the "Install" button is not active.
Have you a suggestion ?

Giuseppe


19. Tuesday, December 08, 2015 at 8:03:34 AM

Hi TMS Team,

is an android version for scanning available at the moment? We have an scanner-handheld with datawedge on it. i''m searching for a simple way to get scanner results.

Zorlu Yusuf


20. Friday, March 11, 2016 at 3:10:52 PM

Hi,

I try to install the package and it works, but when I run with android device 6.0, the button doesn''t show anything.

Thank you

Yudhi Setiawan


21. Saturday, March 12, 2016 at 9:20:08 AM

As the title of this blog implies, this code is for iOS only

Bruno Fierens


22. Wednesday, April 27, 2016 at 7:14:32 AM

Thanks for sharing this nice article. and i wish to again on your new blog keep sharing with your article.
Thanks For Share....

Line scan camera new york


23. Monday, July 18, 2016 at 6:43:10 PM

Version for Android

Renato Souza


24. Wednesday, October 19, 2016 at 9:33:41 PM

Hi!

It''s running okay in my iPod, but in my iPhone 6 with iOS 10.0.2 when I click at the camera icon button crashes the application.

Need help!
Thanks!

Fernando Lucius


25. Thursday, October 20, 2016 at 6:37:25 PM

We''ll need to retest this. There is an external dependency to the zbar lib here. Do you use the latest update of this zbar lib?
Alternatively, I''d suggest to have a look at the new components TTMSFMXNativeBarCodeScanner that is included in TMS iCL: http://www.tmssoftware.com/site/tmsicl.asp that can do barcode scanning without needing any external libs.

Bruno Fierens


26. Monday, October 24, 2016 at 11:18:39 AM

Hi,

Can you try to add the NSCameraUsageDescription key in the project version info? This is a requirement when deploying to iOS 10. More information can be found in the manual of TMS iCL on page 183 (http://www.tmssoftware.biz/Download/Manuals/tmsicldevguide.pdf)


Pieter Scheldeman




Add a new comment:
Author:
Email:
  You will receive a confirmation mail with a link to validate your comment, so please use a valid email address.
Comment:
 
Change Image
Fill in the characters from the image above:
 

All fields are required.
 




Previous  |  Next  |  Index