Jump to content

Recommended Posts

Posted

Hello, to search and display information about a product I have the following scenario:

- a form from where a form is opened with a preview camera and a barcode scanner component:

              FCamera: = TFCamera.Create (nil);
              FCamera.OnReadCode: = ReturnOkCodigo;
              TfgAnimationHelper.ShowForm (FCamera);


- in the form where the image is captured and scanned, I have an accept button that executes this CloseForm (true) code:

 

procedure TFCamera.CloseForm (OK: boolean);
begin
  if OK and Assigned (FOnReadCode) and (fgLabCode.Text <> '-') then FOnReadCode (fgLabCode.Text);

  TfgAnimationHelper.HideForm (Self, [TfgAnimationOption.ReleaseOnFinish]);
  FCamera: = nil;
end;


 The FOnReadCode event helps me to retrieve the code that has been read. This works fine executing like this on click button : CloseForm(true); , but if I use a configuration flag (TConfig.JO.B ['closeonread']) to close the form automatically when a barcode is identified, with this code, a memory error occurs (attach log file):

procedure TFCamera.fgBarcodeScanDetected (Sender: TObject;
  const ABarcodes: TArray <FGX.Scanner.Barcode.TfgBarcode>);
begin
 fgLabCode.Text: = ParseaCodigo (ABarcodes [0] .RawData); //. SubString (HOST_FULL.Length);
 if TConfig.JO.B ['closeonread'] then CloseForm (true) else
  begin
   TThread.ForceQueue (nil, procedure begin
    fgBarcodeScan.Active: = False;
   end);
  end;
end;

 

error_camera_scan_01.png

error_camera_scan_02.png

error_camera_preview.txt

Posted

Hello, Delphi version is 10.4.1, ReturnOkCodigo makes a http request to a rest service to retrive product info and fill a CollectionView, but as I said  if I call by button click the code CloseForm(true) there is no problem, the problem is when is executed on fgBarcodeScanDetected event.

 

error_events.txt

  • Administrators
Posted

Besides the bugfix, please fix the logic as follows:

procedure TFCamera.CloseForm (OK: boolean);
begin
  if FCamera = nil then
    Exit;

  if OK and Assigned (FOnReadCode) and (fgLabCode.Text <> '-') then FOnReadCode (fgLabCode.Text);

  TfgAnimationHelper.HideForm (Self, [TfgAnimationOption.ReleaseOnFinish]);
  FCamera: = nil;
end;

fgBarcodeScanDetected  and TfgAnimationHelper.HideForm both are called asynchronously. 

TfgAnimationHelper.HideForm with TfgAnimationOption.ReleaseOnFinish flag should not be allowed to call more than once, otherwise it will lead to double destruction of the form and memory corruption.

 

Posted
8 часов назад, Viktor Akselrod сказал:

Besides the bugfix, please fix the logic as follows:


procedure TFCamera.CloseForm (OK: boolean);
begin
  if FCamera = nil then
    Exit;

  if OK and Assigned (FOnReadCode) and (fgLabCode.Text <> '-') then FOnReadCode (fgLabCode.Text);

  TfgAnimationHelper.HideForm (Self, [TfgAnimationOption.ReleaseOnFinish]);
  FCamera: = nil;
end;

fgBarcodeScanDetected  and TfgAnimationHelper.HideForm both are called asynchronously. 

TfgAnimationHelper.HideForm with TfgAnimationOption.ReleaseOnFinish flag should not be allowed to call more than once, otherwise it will lead to double destruction of the form and memory corruption.

 

  Hello, thanks for you reply. Closeform is called only once, either when detecting the barcode if the automatic closing flag is set or if the accept button of the form is pressed. Anyway, I add the verification that it tells me.

  • Administrators
Posted

Hello.

TfgAnimationHelper.HideForm(Self, [TfgAnimationOption.ReleaseOnFinish]) - this call does not close immediately form.

first plays the animation, then enqueues the deletion and only then deletes the form.
during this time fgBarcodeScanDetected may fire several more times.

so it is important to prevent for double form destruction.

  • Like 1
Posted
12 минут назад, Viktor Akselrod сказал:

Hello.

TfgAnimationHelper.HideForm(Self, [TfgAnimationOption.ReleaseOnFinish]) - this call does not close immediately form.

first plays the animation, then enqueues the deletion and only then deletes the form.
during this time fgBarcodeScanDetected may fire several more times.

so it is important to prevent for double form destruction.

Ok, I added the check if FCamera = nil then Exit, anyway the memory problem persist, I imagine it will solved with new release, thanks.

  • Administrators
Posted
1 минуту назад, MoreWood сказал:

anyway the memory problem persist, I imagine it will solved with new release

All right. Still need a fix from our side. 

Thank you

  • Thanks 1
  • 3 weeks later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...