Lazarus

Programming => Operating Systems => Android => Topic started by: kristof.project on April 28, 2021, 12:33:03 am

Title: jZBarcodeScannerView crash application
Post by: kristof.project on April 28, 2021, 12:33:03 am
hello,

i create a application LAMW4 [gui] with a main form and 3 other "child" (actRecyclabe). i can switch without probleme
In a child form (scanform) i have a jZBarcodeScannerView. (the permission camera is ok) i can take many photo of codebar, i can close without probleme and go to the main form, but if i want re-open the scanform the app crash. so i re-open the app, i can have scanform and if close it without scan there is no probleme.

the procedure use to call the scanform if you need
Code: Pascal  [Select][+][-]
  1. (...)
  2. procedure TFbase.BscanClick(Sender: TObject);
  3. begin
  4.   if(Fscan = nil) then
  5.  begin
  6.    gApp.CreateForm(TFscan, Fscan);
  7.    Fscan.InitShowing(gApp);
  8.    Fscan.BarCode.Visible:=false;
  9.    Fscan.Bproduit.Visible:=true;
  10.    fscan.Bsignaler.Visible:=false;
  11.    Fscan.Bproduit.Text:='Commercer à scanner';
  12.    DataBase.DataBaseName:='myData.db';
  13.    Fbase.DataBase.Select('SELECT * FROM Produits');
  14.    Fscan.totprod.Text:=IntToStr(Fbase.DataBase.Cursor.GetRowCount)+
  15.    ' produits dans la base';
  16.  end
  17.  else
  18.  begin
  19.    Fscan.Show;
  20.    DataBase.DataBaseName:='myData.db';
  21.    Fbase.DataBase.Select('SELECT * FROM Produits');
  22.    Fscan.totprod.Text:=IntToStr(Fbase.DataBase.Cursor.GetRowCount)+
  23.    ' produits dans la base';
  24.    Fscan.Bproduit.Text:='Commercer à scanner';
  25.    fscan.Bsignaler.Visible:=false;
  26.    Fscan.BarCode.Visible:=false;
  27.    Fscan.Bproduit.Visible:=true;
  28.  end;
  29. end;
  30. (...)
  31.  


Title: Re: jZBarcodeScannerView crash application
Post by: Mongkey on April 28, 2021, 02:14:50 am
just make sure to turn off barcode scan on exit/closing form -> turn on, on barcoder scanner form show
Title: Re: jZBarcodeScannerView crash application
Post by: kristof.project on April 28, 2021, 09:44:22 am
just make sure to turn off barcode scan on exit/closing form -> turn on, on barcoder scanner form show

thank for the idea.i found a procedure stopscan() in jZBarcodeScannerView
so my code in OnScannerResult i use it like this

Code: Pascal  [Select][+][-]
  1. procedure {YouForm}.{Your_jZBarcodeScannerView}Result(Sender: TObject; codedata: string; codeformat: TBarcodeFormat);
  2.  
  3. begin
  4.   {Your_jZBarcodeScannerView}.stopscan();
  5. (...)
  6. end;
  7.  
  8.  

if close my scanform an re-open there no crash.
How i can suggest a modification of AppZBarcodeScannerViewDemo1 ?


Title: Re: jZBarcodeScannerView crash application
Post by: Mongkey on April 28, 2021, 09:57:34 am
I think u should put your code here, i do barcode scanning using lamw, error never comes out by following above procedure. May be we got volunteer to exam your code.
Title: Re: jZBarcodeScannerView crash application
Post by: kristof.project on April 28, 2021, 10:08:59 am
I think u should put your code here, i do barcode scanning using lamw, error never comes out by following above procedure. May be we got volunteer to exam your code.

did you work multiple form ? because i work with, see my previous message.
Title: Re: jZBarcodeScannerView crash application
Post by: Mongkey on April 28, 2021, 10:22:46 am
More than 20 forms,
Title: Re: jZBarcodeScannerView crash application
Post by: kristof.project on April 28, 2021, 10:29:48 am
so the buttonclick to show the scanform

Code: Pascal  [Select][+][-]
  1. procedure TFbase.BscanClick(Sender: TObject);
  2. begin
  3.   if(Fscan = nil) then
  4.  begin
  5.    gApp.CreateForm(TFscan, Fscan);
  6.    Fscan.InitShowing(gApp);
  7.    Fscan.BarCode.Visible:=false;
  8.    Fscan.Bproduit.Visible:=true;
  9.    fscan.Bsignaler.Visible:=false;
  10.    Fscan.Bproduit.Text:='Commercer à scanner';
  11.    DataBase.DataBaseName:='myData.db';
  12.    Fbase.DataBase.Select('SELECT * FROM Produits');
  13.    Fscan.totprod.Text:=IntToStr(Fbase.DataBase.Cursor.GetRowCount)+
  14.    ' produits dans la base';
  15.  end
  16.  else
  17.  begin
  18.    Fscan.Show;
  19.    DataBase.DataBaseName:='myData.db';
  20.    Fbase.DataBase.Select('SELECT * FROM Produits');
  21.    Fscan.totprod.Text:=IntToStr(Fbase.DataBase.Cursor.GetRowCount)+
  22.    ' produits dans la base';
  23.    Fscan.Bproduit.Text:='Commercer à scanner';
  24.    fscan.Bsignaler.Visible:=false;
  25.    Fscan.BarCode.Visible:=false;
  26.    Fscan.Bproduit.Visible:=true;
  27.  end;
  28. end;
  29.  


the buttonscan on formscan

Code: Pascal  [Select][+][-]
  1. procedure TFscan.BscanClick(Sender: TObject);
  2. begin
  3.   if IsRuntimePermissionGranted('android.permission.CAMERA') then
  4.  begin
  5.    Bproduit.Visible:=false;
  6.    BarCode.Visible:=true;
  7.    BarCode.Scan();
  8.  end;
  9. end;

an the procedure onscanresult

Code: Pascal  [Select][+][-]
  1. procedure TFscan.BarCodeScannerResult(Sender: TObject; codedata: string;
  2.   codeformat: TBarcodeFormat);
  3.  
  4.  
  5. begin
  6.   barcode.StopScan();
  7.   if Ord(codeformat)<>13 then
  8.     begin
  9.       infoProd.Text:='';
  10.       Ean.Text:='EAN : Code non valide';
  11.       barcode.visible:=false;
  12.     end
  13.   else
  14.     begin
  15.       Ean.Text:='EAN : '+codedata;
  16.       Fbase.DataBase.Select('SELECT * FROM Produits WHERE EAN='+codedata);
  17.       if Fbase.DataBase.Cursor.GetRowCount<>0 then
  18.         begin
  19.           infoProd.Text:=Fbase.DataBase.Cursor.GetValueAsString('nom');
  20.           Bproduit.visible:=true;
  21.           barcode.visible:=false;
  22.           previmg.visible:=true;
  23.           self.Vibrate(125);
  24.           sleep(250);
  25.           self.Vibrate(125);
  26.           bsignaler.Visible:=false;
  27.           previmg.SetImage(jBitmap1.LoadFromAssets(codedata+'.jpg'));
  28.          end
  29.       else
  30.         begin
  31.           previmg.visible:=false;
  32.           bproduit.visible:=true;
  33.           barcode.visible:=false;
  34.           infoProd.Text:='Produit non trouvé';
  35.           Ean.Text:='EAN : '+codedata;
  36.           self.Vibrate(125);
  37.           bsignaler.Visible:=true;
  38.           Dean:=codedata;
  39.         end;
  40.     end;
  41. end;
     
Title: Re: jZBarcodeScannerView crash application
Post by: Mongkey on April 28, 2021, 10:59:44 am
Try this code on showing your barscan form, Fscan.init(gapp) then fscan.show. Dont forget to stop bar scan on exit activity/form. Even giving result or not on scanning.
Title: Re: jZBarcodeScannerView crash application
Post by: kristof.project on April 28, 2021, 11:35:53 am
Try this code on showing your barscan form, Fscan.init(gapp) then fscan.show. Dont forget to stop bar scan on exit activity/form. Even giving result or not on scanning.

added on the onclose procedure
TinyPortal © 2005-2018