Last report can't be cleared.

Good Day, here is my problem, using the above code i can print my first report correctly, but the next reports are just the same as the first one, after some experimentation i figured out that Report.PrepareReport does not clear the report as it is supposed to do, so what may be the problem ?
Var
  S, TmpName, TmpId: String;
  FrxDataSet: TFrxDBDataSet;
  Report: TFrxReport;
  TmpQ, TmpQ2: TZQuery;
  Stream: TStream;
begin

  TmpName := CurrentEntity.GetEntityName;
  TmpId := IntToStr(GridViewOne.Controller.FocusedRow.Values[0]);

  Report := TFrxReport.Create(FormEntityGrid);
  Report.Clear;

  TmpQ := OpenQuery(Global_Singleton_DbConnection,
    'SELECT REPORT FROM wisp_reports WHERE NAME="' + TmpName +
    '" AND TYPE="SINGLE";').ZQuery;
  Stream := TmpQ.CreateBlobStream(TmpQ.FieldByName('REPORT'), bmRead);
  Stream.Position := 0;
  Report.LoadFromStream(Stream);
  TmpQ.Free;

  S := Global_Singleton_EntityManager.GetEntityByName(TmpName)
    .GetInstanceQueryString(TmpId);

  TmpQ2 := OpenQuery(Global_Singleton_DbConnection, S).ZQuery;

  FrxDataSet := TFrxDBDataSet.Create(Global_Singleton_DbConnection);
  FrxDataSet.UserName := 'Report';
  FrxDataSet.DataSet := TmpQ2;

  Report.DataSets.Items[0].DataSet := FrxDataSet;

  Report.PrepareReport(TRUE);
  Report.ShowReport;

  TmpQ2.Free;

Thanks >

Comments

  • gpigpi
    edited 6:02PM
    Try
    FrxDataSet.Free;
    after
    Report.ShowReport(True);
    comment
    Report.PrepareReport(TRUE);
  • edited 6:02PM
    gpi wrote: »
    Try
    FrxDataSet.Free;
    after
    Report.ShowReport(True);
    comment
    Report.PrepareReport(TRUE);

    Thanks for your reply, but what you suggested does not work > thats because the dataset is actually changing (i cheked the values in debug mode), the problem here is that FastReport is keeping a copy of the last report and use it again and again.
  • edited 6:02PM
    Problem solved after reorganizing my code a little bit, thanks >
      TmpName := CurrentEntity.GetEntityName;
      TmpId := IntToStr(Grid.GridMainView.Controller.FocusedRow.Values[0]);
    
      Report := TFrxReport.Create(FormEntityGrid);
      Report.Clear;
    
      TmpQ := OpenQuery(Global_Singleton_DbConnection,
        'SELECT REPORT FROM wisp_reports WHERE NAME="' + TmpName +
        '" AND TYPE="SINGLE";').ZQuery;
    
      Stream := TmpQ.CreateBlobStream(TmpQ.FieldByName('REPORT'), bmRead);
      Stream.Position := 0;
      Report.LoadFromStream(Stream);
      TmpQ.Free;
    
      S := Global_Singleton_EntityManager.GetEntityByName(TmpName)
        .GetInstanceQueryString(TmpId);
    
      TmpQ2 := OpenQuery(Global_Singleton_DbConnection, S).ZQuery;
    
      FrxDataSet := TFrxDBDataSet.Create(Global_Singleton_DbConnection);
      FrxDataSet.UserName := 'Report';
      FrxDataSet.DataSet := TmpQ2;
    
      Report.DataSets.Items[0].DataSet := FrxDataSet;
    
      Report.PrepareReport(TRUE);
    
      Report.PreviewOptions.Clear;
    
      Report.ShowReport(TRUE);
    
      FrxDataSet.Free;
    
      Report.Clear;
    
      TmpQ2.Free;
    

Leave a Comment