Copy of Data set interferes with returned data

edited October 2018 in FastReport VCL
Hi,

this is a bit of a follow on of this problem I was having with version 4. (though it persists in Version 6 too)
https://www.fast-report.com/en/forum/index....amp;#entry39588

I have a different report that is misbehaving, however it comes down to the same bug in my opinion. I have now proven what the problem is for both the previous mentioned report, as well as this existing report

I have discovered that using a copy of the dataset is very dangerous and leads to unpredictable behavior. I have the following code in my report:

var
StartDate : string;
EndDate : string;
DateTrig : Boolean; // Indicate that the start date has been captured
DS: TfrxDataSet;

procedure mRangeOnAfterData(Sender: TfrxComponent);
begin
DS:=Report.GetDataset('frxDB1'); // Original code from https://www.fast-report.com/en/forum/lofive...p/4/t14219.html
DS.First;
StartDate := FormatDateTime('d mmmm yyyy', DS.Value('seqtime'));
repeat DS.Next
until DS.Eof;
EndDate := FormatDateTime('d mmmm yyyy', DS.Value('seqtime'));
if EndDate <> StartDate then mRange.Memo.Text := StartDate + ' ' + #8211 + ' ' + EndDate
else mRange.Memo.Text := StartDate;
end;

When I run the report, I end up with truncated data! IE rows of data are removed from my report, and on the second page, I always get only 1 row of data. If my report is 1 page or less, than no problem. If I disable the event seen above, or comment out that section of code, then I get all my data presented in the report. So it appears that although I am making a copy of the dataset, and then pointing at the first and finally last record of the dataset (in this case to extract the date), the pointer for my dataset copy is also the main pointer as used by report itself!

For the report mentioned earlier in this topic of mine, this lead to infinite pages being printed of the same data, over and over (see the topic linked above) and again, this was because I was making a copy of the dataset, and then pointing to different data within the dataset.

So, how am I supposed to be interrogating the dataset, without interfering with the reports original dataset pointer?

This is the report with the code seen above Not running (Notice date format is less than ideal, however I have all rows of data on second page as required up to and including the last day of the report)

Comments

  • edited October 2018
    witenite wrote: »
    Hi,

    OK, I found a solution (or workaround, as I consider this to be a bug in FastReports, where the pointer for a copied variable for all intents and purposes actually affects the original variable being copied, in this case the database). My solution was to trigger the event off the main report. The procedure is otherwise identical, but instead of being triggered by the mRange text box (on after data) event, I moved the event to OnStartReport event for the report. See below

  • gpigpi
    edited 3:39PM
    Send small demo project with error to support@fast-report.com

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.