Recent

Author Topic: Lazreport kills the application unpredictably  (Read 15143 times)

sydenis

  • New Member
  • *
  • Posts: 32
Lazreport kills the application unpredictably
« on: July 18, 2021, 05:39:43 pm »
I encountered incomprehensible behavior of Lazreport in different projects.
Usually do like this - I put the frReport1 component on the Datamodule (or on the form) and write the procedure:
Code: Pascal  [Select][+][-]
  1. procedure TdmReport.Print;
  2. begin
  3. frReport1.LoadFromFile('/data/test1.lrf');
  4. frReport1.ShowReport;
  5. end;

In some projects, this call passes without problems. But in other projects, the application crashes when ShowReport is called.
In this case, the following happens:
- No error messages are generated. The app just silently dies.
- The launch under the debbuger passes without errors. The required report opens without problems.

In my last big application, I put frReport1 on one of the forms and tried to call
Code: Pascal  [Select][+][-]
  1. frReport1.LoadFromFile('/data/test1.lrf');
  2. frReport1.ShowReport;
And I got a silent crash of the application.

I did the following experiment:

1. Created a clean project with a main form and a Datamodule with frReport1 component. I have inserted the Print procedure into the Datamodule. And there is only one button on the main form that calls Print.
I launch the application, press the button on the main form - and everything works fine. The report opens.

2. I connect the same Datamodule to my old application through the Project Inspector. In one of the forms, I call Print from the Datamodule and at the time of calling ShowReport, I get an application crash with familiar symptoms:
- No error messages are generated.
- The launch under the debager passes without errors.
I have little experience with Lazreport and I can't understand why in some cases the report opens, and in others the entire application crashes.
Please tell me what I'm doing wrong?

Ubuntu 20.04 + Lazarus 2.0.12

dseligo

  • Hero Member
  • *****
  • Posts: 1194
Re: Lazreport kills the application unpredictably
« Reply #1 on: July 18, 2021, 07:14:04 pm »
Try to catch error like this, maybe it will shed some light on the issue:

Code: Pascal  [Select][+][-]
  1. try
  2.   frReport1.LoadFromFile('/data/test1.lrf');
  3. except
  4.   on E: Exception do ShowMessage(E.Message);
  5. end;
  6.  
  7. try
  8.   frReport1.ShowReport;
  9. except
  10.   on E: Exception do ShowMessage(E.Message);
  11. end;

sydenis

  • New Member
  • *
  • Posts: 32
Re: Lazreport kills the application unpredictably
« Reply #2 on: July 18, 2021, 07:41:59 pm »
Thank you, but no reaction.
The application continues to die silently despite two try ...except blocks

dseligo

  • Hero Member
  • *****
  • Posts: 1194
Re: Lazreport kills the application unpredictably
« Reply #3 on: July 18, 2021, 08:55:35 pm »
Thank you, but no reaction.
The application continues to die silently despite two try ...except blocks

Are you sure it dies here?

See what you get from this:

Code: Pascal  [Select][+][-]
  1. ShowMessage('1');
  2.     try
  3.       frReport1.LoadFromFile('/data/test1.lrf');
  4.     except
  5.       on E: Exception do ShowMessage(E.Message);
  6.     end;
  7. ShowMessage('2');
  8.      
  9.     try
  10.       frReport1.ShowReport;
  11.     except
  12.       on E: Exception do ShowMessage(E.Message);
  13.     end;
  14. ShowMessage('3');

How complex is your report, what do you use in it? Do you have events attached, do you use scripts, do you use user datasets or DBdatasets?
It is strange you can't replicate your problem in new project. This suggests that the problem is somewhere else in your application.

Awkward

  • Full Member
  • ***
  • Posts: 134
Re: Lazreport kills the application unpredictably
« Reply #4 on: July 18, 2021, 10:14:44 pm »
One stupid thing: Are you sure what have all required units in "USES" part? For me, its: "LR_Class, LR_DSet, lrPDFExport, LR_e_img"
maybe you just miss one of unit there?

sydenis

  • New Member
  • *
  • Posts: 32
Re: Lazreport kills the application unpredictably
« Reply #5 on: July 18, 2021, 10:46:55 pm »
How complex is your report
test1.lrf is very simple report with one single text label. See the attachment.
Quote
See what you get from this:
I can see mesages "1" and "2". After - app crash.
Quote
Are you sure what have all required units in "USES" part?
I have only LR_Class in uses. I dont use pdf export, datasets...    this is a verry simpe test report

dseligo

  • Hero Member
  • *****
  • Posts: 1194
Re: Lazreport kills the application unpredictably
« Reply #6 on: July 19, 2021, 01:39:09 am »
Do you have printer installed? I don't know how that works on Ubuntu, but I had crashes on Windows when there were no printers.
Also, check if process is still listed:
Code: Bash  [Select][+][-]
  1. ps afx | grep your_app_name

sydenis

  • New Member
  • *
  • Posts: 32
Re: Lazreport kills the application unpredictably
« Reply #7 on: July 19, 2021, 07:02:44 am »
Also, check if process is still listed:
When the application is not running, the output is as follows:
Code: Pascal  [Select][+][-]
  1. ps afx | grep kzedpass
  2.    6243 pts/1    S+     0:00  |       \_ grep --color=auto kzedpass
When is running (when message "2" is showing):
Code: Pascal  [Select][+][-]
  1. ps afx | grep kzedpass
  2.    6346 pts/0    Ssl+   0:00  |       \_ /data/dev/fbpass/kzedpass
  3.    6388 pts/1    S+     0:00  |       \_ grep --color=auto kzedpass

Quote
Do you have printer installed?
Currently, the printer is not installed on the laptop.  But under debbuger all is fine.
I will try to do all things on Windows tommorow

Fantablup

  • Full Member
  • ***
  • Posts: 169
Re: Lazreport kills the application unpredictably
« Reply #8 on: July 19, 2021, 09:14:49 am »
Just a tip.
You can install a pdf printer instead of a real printer.
I often use this solution.

sydenis

  • New Member
  • *
  • Posts: 32
Re: Lazreport kills the application unpredictably
« Reply #9 on: July 20, 2021, 11:50:23 am »
On Windows10 with Xerox printer application works fine.
On Ubuntu with Pantum printer application die
Printers are connected via network
« Last Edit: July 20, 2021, 11:52:05 am by sydenis »

sydenis

  • New Member
  • *
  • Posts: 32
Re: Lazreport kills the application unpredictably
« Reply #10 on: July 23, 2021, 11:34:01 am »
After all, this is a very strange thing )
I tried to repeat everything on Lazarus 2.2.   
The same situation. In debug mode, the report opens well. During normal startup, the application crashes.
But in 2.2 now there is a message:
Execution stopped with exit code 1 ($0001)

sydenis

  • New Member
  • *
  • Posts: 32
Re: Lazreport kills the application unpredictably
« Reply #11 on: July 30, 2021, 12:31:24 am »
I think I've figured out where is the problem.

The form that called the report had the  property FormStyle set to fsStayOnTop.
If you disable it then the Report opens normally. If it is enabled, the application behaves unpredictably:

in 99% of cases, the application crashes, in 1% - the report opens well.
And there is no chance to intercept the error with a debuger.

Maybe it will be useful to someone )

jesusr

  • Sr. Member
  • ****
  • Posts: 484
Re: Lazreport kills the application unpredictably
« Reply #12 on: July 30, 2021, 07:54:27 am »
Add to your uses the unit LCLExceptionStackTrace and check if at least it dumps a backtrace. If the program is simple create a test project.

sydenis

  • New Member
  • *
  • Posts: 32
Re: Lazreport kills the application unpredictably
« Reply #13 on: July 30, 2021, 10:54:17 am »
After adding LCLExceptionStackTrace, nothing changes in the behavior of the debuger. He behaves the same way as I wrote in the first posts.

It's easy to repeat the situation:
- Create new project
- Put the on the main form TfrReport and TButton component
- Create a primitive report with a single text field
- Code for the Button:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   frReport1.LoadFromFile('my_test_report.lrf');
  4.   frReport1.ShowReport;
  5. end;
- Set the FormStyle = fsStayOnTop property for the main form
- Launch the application and try to open the report

Then set the breakpoint to frReport1.ShowReport and launch the application with the debugger

Then remove the fsStayOnTop and try to launch the application again - all is fine ))
« Last Edit: July 30, 2021, 11:00:27 am by sydenis »

balazsszekely

  • Guest
Re: Lazreport kills the application unpredictably
« Reply #14 on: July 30, 2021, 11:31:55 am »
@sydenis
It works fine for me with Lazarus Trunk/FPC 3.2.0/Win10. There is no crash with fsStayOnTop.

 

TinyPortal © 2005-2018