Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Error loading report

Hello

I’m using a custom ReportExplorer, and sometimes — only occasionally — a report does not load. However, if I select another report in the same folder, it loads correctly.

Initially, I was loading the report using:

FReportExplorer.PrintPreview(FListView.ItemName, FListView.FolderId)

When the issue occurs, this call does nothing and no exception is raised.
I changed it to:

LoadReport(FListView.ItemName, FListView.FolderId)

With this method, an exception is raised indicating that the report cannot be found.

I’ve noticed that when this happens, FListView.FolderId has the value -1.

To work around this, I switched to loading reports using LoadFromDatabase, but the problem still occurs (although less frequently).

It's important to mention that I previously used Delphi 7 with an older version of ReportBuilder, and this issue never happened. The problem only started after upgrading to delphi 12.2 and the current version.

Do you have any guidance on why FolderId might intermittently be -1, or how to ensure reports load reliably in this scenario?

Thanks you

Comments

  • Hi Felix,

    This is not a known issue with the latest version of ReportBuilder.

    As you mentioned, the issue appears to be when the FListView.FolderID is -1. ReportBuilder does not explicitly set the FolderID to -1 so it must be a specific case that causes the behavior.

    Try using the built-in report explorer and see if the problem persists. If so, please create a simple example that demonstrates the issue and send it to us in .zip format and we'll research a solution. Send all files to support@digital-metaphors.com
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • Hi
    The issue is that the error occurs randomly, and I need to use a CustomReportExplorer. Is there any way to control the FolderId value?

    Thank you
  • Hi again
    Or is there any other way to load the report by its Report ID?

    thank you
  • Hi
    Sorry, the one that has the value -1 is FListView.ItemId, although FListView.ItemName has the correct value and FolderId also has the correct value.

    Thank you
  • Hi Felix,

    Based on your description, it may be that the issue is only caused by new reports added while your application is open. In this case, it's possible the dataset is not refreshed and the ItemID is (temporarily) incorrect. Try setting the Item pipeline's RefreshAfterPost property to True and see if that helps the issue.

    If the above doesn't help, take a look at the following article on how to locate a report from the Report Explorer without the use of the ItemID.

    https://rbwiki.digital-metaphors.com/design/templates/how-to-programmatically-load-reports-saved-using-the-report-explorer/
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • Thanks, nicocizik.
    The error does not occur with new reports; it always happens with existing ones. It can happen with any report: a report that displays correctly may fail to show the next time. I’m already using LoadFromDataBase, and although the error seems to happen less frequently, it still occurs, and honestly, it really confuses my clients. Since it’s a random error, I can’t reproduce it either.

    I’ve checked that the report dataset is positioned correctly, but the error still appears.
    Do you have any additional hints on what I could look into?
    Is there any exception I can catch that might give me more information about why this is happening?
  • edited December 5
    Hi Felix,

    Unfortunately without a reproducible example, there is not much else we can recommend as far as RB-based work-arounds.

    Perhaps more background on how your application functions. At what point are you calling LoadReport? Is it being called in a loop? How are you certain a report has been selected in the explorer? Are you certain the report exists in the DB?

    You mention in your first post that FolderID is -1, but in your 4th post, ItemID is -1. This would imply that the LocateItemRecord routine is returning false for certain reports. (see the TppItemList.GetItemId routine in the ppRptExp.pas file).

    The key is to find out why the LocateItemRecord is unable to find a report however, being able to recreate this yourself will make this difficult. I suggest using a profiler such as MadExcept to track the call stack and parameters sent to these routines when the problem occurs on your users' machines.
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • Hi Nico

    I have some doubts about how ReportBuilder loads the reports. In the example
    https://rbwiki.digital-metaphors.com/design/templates/how-to-programmatically-load-reports-saved-using-the-report-explorer/

    how is the value of FFolderID obtained?

    I’m testing it using the LoadFromDatabase method, and the result of the ReportLocateRecordEvent does not seem to affect how the report is loaded — even if it returns false, the report still loads correctly. I think I’m doing something wrong.
  • Hi Nico

    I’ll explain how the application works. There are two ways to load a report: if the user clicks Print, the default report is printed. Previously, I loaded it using LoadReport. It also caused issues, so I changed it to LoadFromDatabase, and in ReportLocateRecordEvent, since I have the report code, I perform a Locate by the report code.

    If the user right-clicks Print, the explorer opens, allowing them to select a report, and for example in PrintPreview I do:

    if (FListView.ItemName = '') then
    Exit;

    FReportExplorer.PrintPreview(FListView.ItemName, FListView.FolderId);

    This didn’t raise an error, but it would not open the report, so I changed it to:

    LoadReport(FListView.ItemName, FListView.FolderId);

    which does raise an exception when the report cannot be found. When the error occurs, ItemName and FolderId have the correct values, but ItemId is -1.

    Now I’m using LoadFromDatabase, and in ReportLocateRecordEvent I perform a Locate by FolderId and ItemName.

    The reports do exist — a report that previously opened correctly may fail to load the next time, and vice versa.

    I’ve used this same system for loading reports for years in another company with Delphi 7 and never had this issue.

    As I mentioned, I can’t reproduce the error — it occurs randomly. I’m going to try using EurekaLog to capture the error, and I’ll get back to you with the results.

    Thank you
  • Hi Felix,

    The FolderID is necessary to locate a report in the rbItem table. This is due to the fact that reports can have the same name in different folders. For the article, it implies the report is being loaded without the use of the Explorer so the FolderID must be obtained manually elsewhere (in code or from another DB enabled component).
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
Sign In or Register to comment.