Reading Delphi xe7 barcode, event after intent does not fire

In my application developed with XE7 for Android / iOS, I have a form for scanning barcodes. Based on the barcode found, my application checks whether it is an acceptable barcode or not. Below are the following tutorials: http://www.fmxexpress.com/qr-code-scanner-source-code-for-delphi-xe5-firemonkey-on-android-and-ios/

I am currently testing Android, and I can integrate scanning and reading barcodes, but the onBarCode event does not fire when a barcode search is returned from the total activity. The same code worked well with previous versions of Rad Studio (XE4, XE5, XE6), but now this is not the case in XE7.

Here are some code snippets:

... begin Scanner := TAndroidBarcodeScanner.Create(true); Scanner.OnBarCode := BarcodeHandler; Scanner.Scan; end; procedure TmScannerForm.BarcodeHandler(Sender: TAndroidBarcodeScanner; BarCode: String); begin text1.Text := Barcode; memo1.PasteFromClipboard; AddBarcode(BarCode, true); end; 

AddBarCode - I even used it to check and add a barcode to the list, but I did not include it, because this code is not a problem - it does not even start. Text1.text: = Barcode and memo1.paseFromClipboard were for checking them, they didnโ€™t even shoot. I can confirm that the barcodes are read, because if I click and manually insert, the barcode shows.

Why does this not work on XE7, as it was in previous versions of Rad Studio?

+6
source share
4 answers

Andrea Magni has a more elegant solution than a timer on his blog based on event handling.

I would comment to send the link, but I do not have enough reputation. Link to his blog:

http://blog.delphiedintorni.it/2014/10/leggere-e-produrre-barcode-con-delphi.html

Maybe this can help you. The blog is in Italian, but sources are provided and they themselves explain.

+5
source

There is a source code snippet at http://john.whitham.me.uk/xe5/ that looks applicable (based on Zxing):

  intent := tjintent.Create; intent.setAction(stringtojstring('com.google.zxing.client.android.SCAN')); sharedactivity.startActivityForResult(intent,0); 

The code in the related article also shows how to get an Intent result. (I donโ€™t work with Delphi on Android, so I'm not sure if this part uses the best practice - TTKRBarCodeScanner uses a workaround with a timer and clipboard).

I would try this as an alternative to see if it works.

+2
source

This code works for me!

When running the scan code, set the timer to true.

 procedure Tform.Timer1Timer(Sender: TObject); begin if (ClipService.GetClipboard.ToString <> '') then begin timer1.Enabled:=false; zSearch.Text := ClipService.GetClipboard.ToString; //Do what you need end; end; 
+1
source

This code works great for me!

in andorid.BarcodeScanner

 function TAndroidBarcodeScanner.HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean; var aeBecameActive : TApplicationEvent; begin aeBecameActive := TApplicationEvent.BecameActive; if FMonitorClipboard and (AAppEvent = aeBecameActive) then begin GetBarcodeValue; end; end; 
+1
source

Source: https://habr.com/ru/post/976217/


All Articles