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


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 :

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);
  // line1: activate the code scanner. This shows the camera that should be aimed at the QR or UPC code

procedure TForm1136.TMSFMXZBarReader1GetResult(Sender: TObject;
  AResult: string);
  //line 2: the OnGetResult event is triggered when the code was retrieved and this returns it as a text
  ListBox1.Items.Insert(0, AResult);

You can download the sample project and the package with full source code to install the TTMSFMXZBarReader component here:
Open the package file TMSFMXZBarReaderPkgDXE5.dproj from Delphi XE5 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 …


Comments are closed.