Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

1 MONTH VIP - 5$; 3 MONTHS VIP - 10$; 6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Barcode Capturing with Delphi XE4 iOS App!

Discussion in 'Delphi Android And IOS' started by N0body, Jan 7, 2014.

  1. N0body
    Online

    N0bodyN0body is a Verified Member DelphiFan Administrator Staff Member DF Staff

    Hello Everyone!


    See in this article how to read and decode barcodes through an Delphi XE4 iOS App. The process consists in capturing an image using the device camera and decoding it through a specialized SDK.


    CodeBar Libraries for iOS Apps
    There are a lot of SDKs focused in barcode decoding, supporting numerous platforms, some paid, some free, with different levels of features, just go to Google and you’ll receive a huge list of suggestions to explore. Here, we are interested in SDKs for the iOS platform.


    In general, these SDKs are created to be used with Objective-C, so we need to translate the SDK’s header to Pascal through one of the available ways. Here you can find more information about the translation process:


    http://alturl.com/v2wtx


    http://alturl.com/y87xb


    To create this sample, I’m using the ZBar SDK (http://zbar.sourceforge.net/), an open source library, which has its header translated to Pascal by Simon Choi, originally published here: http://blog.naver.com/simonsayz/120175561755.


    Developing the App
    Once you have the SDK (in this case represented by a file called "libzbar.a") and the header translation in  hands, you can create a Delphi class to expose the SDK methods in a easy and friendly way to your iOS app. See below how this class looks:


    Code:
     TZBarCode = class(TObject)
      private
        ZBarView: ZBarReaderView;
        ZBarEvent: TZBarReaderViewDelegate;
        FActive: Boolean;
        function GetActive: Boolean;
        procedure SetActive(value: Boolean);
        function GetOnBarCode: TOnBarCode;
        procedure SetOnBarCode(value: TOnBarCode);
      protected
        destructor Destroy; override;
      public
        constructor Create; virtual;
        procedure Free;
        procedure SetFrame(View: UIView; Frame: CGRect);
        property Active: Boolean Read GetActive Write SetActive;
        property OnBarCode: TOnBarCode Read GetOnBarCode Write SetOnBarCode;
      end;
    [size=78%]
    Building the Visual Interface
    Considering the visual part of the application, we have:


    - An TEdit (edtResult) to receive the barcode data;


    - An TMemo (memImage) to define the image display area;


    - An TListBox (lstHistory) to store the capture log;


    - An TSwitch (swtONOFF) to activate/deactivate the capture process;


    - An TButton (btnCopy) to copy the barcode data to the clipboard;


    - An TButton (btnClear) to clear the capture log;


    You can see the expected form appearance in this image:


    [​IMG]



    Adding Some Code
    Start by adding - in the private section of the main application form - one field to instantiate our capture class and a method to be assigned to the capture event:


      [/size]
    Code:
    private
        { Private declarations }
        ZBarCode: TZBarCode;
        procedure OnFindBarCode(Sender: TObject; BarCode: String);
      public
    Looking to the OnFindBarCode event, the BarCode variable brings the captured value, so you just need to assign it to the edtResult, as well to the lstHistory to create the log:
    
    
    procedure TMainForm.OnFindBarCode(Sender: TObject; BarCode: String);
    begin
      edtResult.Text := BarCode;
      lstHistory.Items.Add(FormatDateTime('dd/mm/yyyy hh:nn:ss', Now) + ' - ' + BarCode);
    end;
    Using the OnSwitch event from TSwitch, we’ll instantiate the capture’s class, assign the capture event, as well as define the image plotting area, and finally start the capture:
    
    
    procedure TMainForm.swtONOFFSwitch(Sender: TObject);
    begin
      if not Assigned(ZBarCode) then
      begin
        ZBarCode := TZBarCode.Create;
        ZBarCode.OnBarCode := OnFindBarCode;
        ZBarCode.setFrame(WindowHandleToPlatform(Self.Handle).View,
          CGRectMake(memImage.Position.X, memImage.Position.Y, memImage.Width,
          memImage.Height));
      end;
      ZBarCode.Active := swtONOFF.IsChecked;
    end;
    To complete the app, here is the code for the two added buttons:
    
    
    procedure TMainForm.butClearClick(Sender: TObject);
    begin
      edtResult.Text := '';
      lstHistory.Items.Clear;
    end;
    procedure TMainForm.btnCopyClick(Sender: TObject);
    begin
      edtResult.SelectAll;
      edtResult.CopyToClipboard;
    end;
    [size=78%]
    Note: This app is intended to run only in a real device. Here you can see the app in action:


    [​IMG]


    [/size]You can download the sample with the complete source code here: [/size]
    [/size]http://cc.embarcadero.com/item/29485
     
  2. whitewarriortr
    Offline

    whitewarriortr DF Junior

    Teşekkürler.
    Thanks.
     
  3. ASAPLTDA
    Offline

    ASAPLTDA DF Junior

    HOLA EXISTE PARA ANDROIT?
     
     

Share This Page

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block