FR6 not handling dataset' events the same as FR5, causing problems.

edited May 2018 in FastReport VCL
Hello,

I've just had some reports from users that since changing to FR6 some of my reports are showing incorrect data.

Looking into it, what I can see is that the "OnFirst", "OnNext", "OnPrior" events from a TfrxDBDataset are being called, but the linked dataset cursor is apparently not being changed between records.

For instance, I have a master-detail-subdetail report. For speed reasons, I load the whole resultset into memory tables. This tables are linked each one to a TfrxDBDataset. using the OnFirst, OnNext, OnPrior events I set a filter into the corresponding detail dataset, using the value of the parent record.

So, for the Master dataset, corresponding to table A, on the OnFirst/... events I set a filter on the detail dataset, table B, using tableA->FieldByName("Id"). On B, I set a filter on it's detail dataset, table C, using tableB->Id. And so on.

The problem is that even if the events are being called correctly, the corresponding value on the linked dataset is not changed, as if the linked dataset was not being advanced. The values printed on the report are incorrect (as the details/subdetails don't correspond to the correct parent).

Building this with FR5 works fine (as it was working before changing FR version)

Is there something changed between FR5 and FR6 that needs to be addressed for this to work again?

I've tried this with FR 6.0.10 and FR 6.1 with the same results.

Comments

  • edited May 2018
    This problems actually happen also with FR5, with versions > 5.6.8 (or so I think).

    <strike>Maybe the culprit is this fix: "- Fixed issue when used RangeEnd = reCount to limit records of the dataset" in version 5.6.12?</strike> I thought the problem was that, but I reinstalled 5.6.12 and this still happens. I moved back to the previous installer I had, 5.6.8, and with that version this works fine.


    When running with the BPLs of version 5.6.8 the reports are generated correctly. When using 5.6.12+ then I get the errors. This is with *exactly* the same executable, the only thing that changes is the runtime packages of FR.

    I added some logging to the OnFirst/OnNext events to try to see what's happening and I see the following:

    For the correct run, this is the log:
    2018-05-08 16:23:00.686+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRPautasContratoFirst] Filtrando d?­as para la Pauta Id: 74816 (74816)
    2018-05-08 16:23:00.686+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRPautasContratoFirst]   CachedQueryDias->RecordCount: 2
    2018-05-08 16:23:00.687+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRDiasPautaContratoFirst] Filtrando spots para DiaPautaContratoId: 619336, Pauta Id: 74816
    2018-05-08 16:23:00.688+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRDiasPautaContratoFirst]   CachedQuerySpots->RecordCount: 2
    2018-05-08 16:23:00.702+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRDiasPautaContratoFirst] Filtrando spots para DiaPautaContratoId: 619336, Pauta Id: 74816
    2018-05-08 16:23:00.702+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRDiasPautaContratoFirst]   CachedQuerySpots->RecordCount: 2
    2018-05-08 16:23:00.703+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRDiasPautaContratoNext] Filtrando spots para DiaPautaContratoId: 619337, Pauta Id: 74816
    2018-05-08 16:23:00.703+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRDiasPautaContratoNext]   CachedQuerySpots->RecordCount: 2
    2018-05-08 16:23:00.703+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRDiasPautaContratoNext] Filtrando spots para DiaPautaContratoId: 619337, Pauta Id: 74816
    2018-05-08 16:23:00.703+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRDiasPautaContratoNext]   CachedQuerySpots->RecordCount: 2
    2018-05-08 16:23:00.703+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRPautasContratoNext] Filtrando d?­as para la Pauta Id: 74817 (74817)
    2018-05-08 16:23:00.703+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRPautasContratoNext]   CachedQueryDias->RecordCount: 2
    2018-05-08 16:23:00.704+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRDiasPautaContratoFirst] Filtrando spots para DiaPautaContratoId: 619338, Pauta Id: 74817
    2018-05-08 16:23:00.704+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRDiasPautaContratoFirst]   CachedQuerySpots->RecordCount: 1
    2018-05-08 16:23:00.705+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRDiasPautaContratoFirst] Filtrando spots para DiaPautaContratoId: 619338, Pauta Id: 74817
    2018-05-08 16:23:00.705+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRDiasPautaContratoFirst]   CachedQuerySpots->RecordCount: 1
    2018-05-08 16:23:00.705+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRDiasPautaContratoNext] Filtrando spots para DiaPautaContratoId: 619339, Pauta Id: 74817
    2018-05-08 16:23:00.705+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRDiasPautaContratoNext]   CachedQuerySpots->RecordCount: 1
    2018-05-08 16:23:00.705+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRDiasPautaContratoNext] Filtrando spots para DiaPautaContratoId: 619339, Pauta Id: 74817
    2018-05-08 16:23:00.705+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRDiasPautaContratoNext]   CachedQuerySpots->RecordCount: 1
    2018-05-08 16:23:00.705+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRPautasContratoNext] Filtrando d?­as para la Pauta Id: 74817 (74817)
    2018-05-08 16:23:00.705+05:00     23107406     5932 [$0/0] INFO  default [20020] [ThreadId: 5932] [TROrdenDeServicio::frxDSTbRPautasContratoNext]   CachedQueryDias->RecordCount: 2
    

    For a run with the latest versions, I get the following log:
    2018-05-08 16:23:55.183+05:00     23161796    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRPautasContratoFirst] Filtrando d?­as para la Pauta Id: 74816 (74816)
    2018-05-08 16:23:55.183+05:00     23161796    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRPautasContratoFirst]   CachedQueryDias->RecordCount: 2
    2018-05-08 16:23:55.184+05:00     23161796    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRDiasPautaContratoFirst] Filtrando spots para DiaPautaContratoId: 619336, Pauta Id: 74816
    2018-05-08 16:23:55.185+05:00     23161796    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRDiasPautaContratoFirst]   CachedQuerySpots->RecordCount: 2
    2018-05-08 16:23:55.203+05:00     23161812    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRDiasPautaContratoFirst] Filtrando spots para DiaPautaContratoId: 619336, Pauta Id: 74816
    2018-05-08 16:23:55.203+05:00     23161812    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRDiasPautaContratoFirst]   CachedQuerySpots->RecordCount: 2
    2018-05-08 16:23:55.203+05:00     23161828    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRDiasPautaContratoNext] Filtrando spots para DiaPautaContratoId: 619336, Pauta Id: 74816
    2018-05-08 16:23:55.203+05:00     23161828    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRDiasPautaContratoNext]   CachedQuerySpots->RecordCount: 2
    2018-05-08 16:23:55.203+05:00     23161828    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRDiasPautaContratoNext] Filtrando spots para DiaPautaContratoId: 619337, Pauta Id: 74816
    2018-05-08 16:23:55.204+05:00     23161828    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRDiasPautaContratoNext]   CachedQuerySpots->RecordCount: 2
    2018-05-08 16:23:55.204+05:00     23161828    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRPautasContratoNext] Filtrando d?­as para la Pauta Id: 74816 (74816)
    2018-05-08 16:23:55.204+05:00     23161828    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRPautasContratoNext]   CachedQueryDias->RecordCount: 2
    2018-05-08 16:23:55.205+05:00     23161828    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRDiasPautaContratoFirst] Filtrando spots para DiaPautaContratoId: 619336, Pauta Id: 74816
    2018-05-08 16:23:55.205+05:00     23161828    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRDiasPautaContratoFirst]   CachedQuerySpots->RecordCount: 2
    2018-05-08 16:23:55.206+05:00     23161828    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRDiasPautaContratoFirst] Filtrando spots para DiaPautaContratoId: 619336, Pauta Id: 74816
    2018-05-08 16:23:55.206+05:00     23161828    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRDiasPautaContratoFirst]   CachedQuerySpots->RecordCount: 2
    2018-05-08 16:23:55.206+05:00     23161828    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRDiasPautaContratoNext] Filtrando spots para DiaPautaContratoId: 619336, Pauta Id: 74816
    2018-05-08 16:23:55.206+05:00     23161828    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRDiasPautaContratoNext]   CachedQuerySpots->RecordCount: 2
    2018-05-08 16:23:55.206+05:00     23161828    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRDiasPautaContratoNext] Filtrando spots para DiaPautaContratoId: 619337, Pauta Id: 74816
    2018-05-08 16:23:55.207+05:00     23161828    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRDiasPautaContratoNext]   CachedQuerySpots->RecordCount: 2
    2018-05-08 16:23:55.207+05:00     23161828    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRPautasContratoNext] Filtrando d?­as para la Pauta Id: 74817 (74817)
    2018-05-08 16:23:55.207+05:00     23161828    12376 [$0/0] INFO  default [20020] [ThreadId: 12376] [TROrdenDeServicio::frxDSTbRPautasContratoNext]   CachedQueryDias->RecordCount: 2
    

    As you can see, the Next doesn't really appear to have moved the cursor in the dataset until the last call (the one that gets to Eof, I assume). In the correct run the Next has correctly changed the current record. This happens for the two details here: RPautas and RDiasPauta.

    Any ideas on how to solve this? Is it a bug, or some setting that needs to be changed from 5.6.8+ ?
  • edited May 2018
    Looking at the code in frxDBSet.pas I see this in the non-working versions:
    procedure TfrxDBDataSet.Next;
    var
      b: TBookmark;
    begin
      if not FInitialized then
        Open;
      FEof := False;
      if RangeEnd = reCurrent then
      begin
        b := FDS.GetBookmark;
        if FDS.CompareBookmarks(b, FBookmark) = 0 then
          FEof := True;
        FDS.FreeBookmark([img]style_emoticons/<#EMO_DIR#>/cool.gif" style="vertical-align:middle" emoid="B)" border="0" alt="cool.gif" />;
      end;
      inherited Next;
      if ((RangeEnd = reCurrent) or (RangeEnd = reCount)) and Inherited Eof then
        Exit;
      FDS.Next;
    end;
    

    The previous version, which works, is:
    procedure TfrxDBDataSet.Next;
    var
      b: TBookmark;
    begin
      if not FInitialized then
        Open;
      FEof := False;
      if RangeEnd = reCurrent then
      begin
        b := FDS.GetBookmark;
        if FDS.CompareBookmarks(b, FBookmark) = 0 then
          FEof := True;
        FDS.FreeBookmark([img]style_emoticons/<#EMO_DIR#>/cool.gif" style="vertical-align:middle" emoid="B)" border="0" alt="cool.gif" />;
        if FEof then
          Exit;
      end;
      FDS.Next;
      inherited Next;
    end;
    

    I'm guessing that the problem comes because the inherited Next call is setting the Eof flag, then the new validation occurs which ends the procedure without calling the Next on the FDS. In the case I'm checking it's easy to see the problem as there are only 2 records, probably if there were more records only the last one would be repeated.

    As I don't know why the code was changed as it was, I don't know if moving the FDS.Next before the inherited Next in the new code is the correct solution or if it is like this for some particular reason. Anyone from FR care to comment?
  • PolomintPolomint Australia
    edited May 2018
    Can't comment directly on your issue, but good to see you've put some effort into solving it yourself 😎

    Have you raised a Ticket with Support? I find they are pretty quick to respond.

    https://support.fast-report.com

    Cheers, Paul
  • edited May 2018
    Hello Paul,
    Polomint wrote: »
    Have you raised a Ticket with Support? I find they are pretty quick to respond.

    I haven't. I didn't know if it was indeed a bug or just something I needed to change in the configuration or settings of the report. Looking at the code I do believe now it is a bug, but I wonder why nobody else has reported it? Anyway, I changed the code in FR6, rebuilt and now my reports are working fine again. I will create a ticket anyway to let FR know directly and maybe they can confirm if the solution is correct or something else is going on.

    Thanks

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.