Show a second copy of a report, keeping first one on screen?

hsmhsm
edited 10:00AM in FastReport 4.0
How can I show a second copy of a report in preview while the first copy of the report is still displayed on the screen?

I need to do this as in my application the user makes choices from a menu and those choices are used to build the SQL that creates the dataset for the report.
The report is then shown using ShowReport(true);

For example, the user might choose to see a report to do with students' grades for year 11.
Then - while that year 11 report is still in preview (with modal = false) - they go back to the menu and choose to see the same report but this time for year 12.

I know that by setting my report's modal property to false I can open report B while I still have report A displayed in preview. But at the moment, even with modal = false, the year 11 report gets replaced by the year 12 one if I choose the same report.

Howard

Comments

  • gpigpi
    edited 10:00AM
    wrote:
    The report is then shown using ShowReport(true);
    Use
    frxReport1.LoadFromFile('1.fr3');
    frxReport1.PrepareReport(True);
    frxReport1.LoadFromFile('2.fr3');
    frxReport1.PrepareReport(False);
    frxReport1.ShowPreparedReport;
    
  • hsmhsm
    edited 10:00AM
    gpi wrote: »
    Use
    frxReport1.LoadFromFile('1.fr3');
    frxReport1.PrepareReport(True);
    frxReport1.LoadFromFile('2.fr3');
    frxReport1.PrepareReport(False);
    frxReport1.ShowPreparedReport;
    

    Thank you gpi,
    However I currently don't save any reports to a file so there is nothing to load. Where did the 1.frs and 2.fr3 files you are loading come from?

    If they are the report design saved to a file does this mean I need to save, and distribute, as many duplicate copies of my report as there are menu choice combinations creating the sql.? There could be quite a few (around 60 that I can think of and that's just for one report eg 4 year groups, 6 houses, 2 genders, 40 registration groups plus options on the field the report is grouped by)
  • gpigpi
    edited 10:00AM
    wrote:
    Where did the 1.frs and 2.fr3 files you are loading come from?
    Application folder
    wrote:
    If they are the report design saved to a file does this mean I need to save, and distribute, as many duplicate copies of my report as there are menu choice combinations creating the sql.? There could be quite a few (around 60 that I can think of and that's just for one report eg 4 year groups, 6 houses, 2 genders, 40 registration groups plus options on the field the report is grouped by)
    Use
    frxReport1.PrepareReport(True);
    frxReport1.PrepareReport(False);
    frxReport1.ShowPreparedReport;
    
  • hsmhsm
    edited 10:00AM
    gpi wrote: »
    Application folder Use
    frxReport1.PrepareReport(True);
    frxReport1.PrepareReport(False);
    frxReport1.ShowPreparedReport;
    

    Thanks for the suggestion gpi, but that didn't make any difference. The second report overwrites the first instead of appearing in a new preview window.
    Also, using those lines instead of just frxReport1.ShowReport(true), I get an error from the ClientDataset that supplies the data to the report (via a frxDBDataset) - 'No index currently active'. I set up various indexes before showing the report to alter the sort order depending upon the choices the user makes.
  • gpigpi
    edited 10:00AM
    wrote:
    The second report overwrites the first instead of appearing in a new preview window.
    My code should add second report to first.

    You can use only one preview for one TfrxReport instance
  • hsmhsm
    edited 10:00AM
    wrote:
    You can use only one preview for one TfrxReport instance

    Thats what I was begininning to suspect.
    Is it possible therefore to create a second instance of a TfrxReport?

    Currently I have the TrfxReport object placed on a form because that is so much easier.
    Does this mean that I wouild need to create the report dynamically, using something like
    MyReport := TrfxReport.create?

    If so I've no idea how I would set all the elements of this report up. (The report in question is a cross tab report containing several interactive elements and quite a bit of code that manipulates what is shown in the cells and how it is dislayed.)

    Maybe I've reached a limitation of FastReport

    Howard
  • edited 10:00AM
    hsm wrote: »

    Maybe I've reached a limitation of FastReport
    IIRC FR uses a few global variables which will probably always give a problem for creating 2 reports in parallel.
  • gpigpi
    edited 10:00AM
    Use
    frxReport1.SaveToStream(MemoryStream);
    MemoryStream.Position := 0;
    frxReport2.LoadFromStream(MemoryStream);
    
  • Zhou X.B.Zhou X.B. Indonesia
    edited 10:00AM
    hsm wrote: »

    Thats what I was begininning to suspect.
    Is it possible therefore to create a second instance of a TfrxReport?

    Currently I have the TrfxReport object placed on a form because that is so much easier.
    Does this mean that I wouild need to create the report dynamically, using something like
    MyReport := TrfxReport.create?

    If so I've no idea how I would set all the elements of this report up. (The report in question is a cross tab report containing several interactive elements and quite a bit of code that manipulates what is shown in the cells and how it is dislayed.)

    Maybe I've reached a limitation of FastReport

    Howard

    I faced a similar difficulty as you did Howard. For now, I got a temporary solution by coding like this:
    - update the source of Fast Report ie. frxPreview.pas

    procedure TfrxPreview.RefreshReport;
    var
    hpos, vpos, pno: Integer;
    begin
    //if not Assigned(Report) then exit; // just don't user the Refresh feature
    Exit;

    hpos := FWorkspace.FOffset.X;
    vpos := FWorkspace.FOffset.Y;
    pno := FPageNo;

    Lock;
    FRefreshing := True;
    try
    Report.PrepareReport;
    FLocked := False;
    FThumbnail.Locked := False;
    if pno <= PageCount then
    FPageNo := pno
    else
    FPageNo := 1;
    UpdatePages;
    UpdateOutline;
    finally
    FRefreshing := False;
    end;

    FWorkspace.FOffset.X := hpos;
    FWorkspace.FOffset.Y := vpos;
    FWorkspace.Locked := False;
    FWorkspace.Repaint;
    FThumbnail.Repaint;
    if pno > PageCount then
    PageNo := 1;
    end;


    - don't use ShowReport, but
    ...
    PrepareReport;
    ShowPreparedReport;


    There are drawbacks w/ this ad hoc solution:
    - user must wait until the full report prepared before the preview window showed
    - we can not utilize the auto-refresh ability of fastreport, which is good for some occasions

    Actually, Fastreport preview engine is a dynamic preview, while what we wanted is a static one.
    Hope this can help.

    Zhou

Leave a Comment