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

Skipping Detail Records

edited July 2002 in General
I've tried to implement skipping of detail records based on a certain
condition, as done in demo #116. However, the problem is when the last
record should be skipped, there are problems.

For example, see demo #116. Edit the BIOLIFE demo database, and add a new
record, where the "Common_Name" field begins with an 'S'. Then, run demo
#116. The report generates an infinite amount of pages, until you click
"Cancel". Is there a bug with the approach in demo #116? Everything seems
to work OK with this way of doing things, unless the last record in the
dataset should be skipped.

Comments

  • edited July 2002
    The demo was checking Category in the SkipForward and Common_Name in
    SkipBackward, which obviously is a mistake on our part. They should both be
    checking Category to get the 18 records as the form states. The last
    record's category value is Smelt, which starts with an S. In the while
    loops, there are checks for EOF or BOF so that an infinite loop is not
    incurred. It will work correctly if they are both set to Category. Sorry
    and thanks for pointing this out.


    Cheers,

    Jim Bennett
    Digital Metaphors

  • edited July 2002
    The problem I'm still having is when no records should be returned in the
    report, it still prints out the last record in the dataset. I've followed
    along with the demo at:

    http://www.digital-metaphors.com/tips/NoDetailOnSkipRecords.zip

    under the "Skipping Records Advice" thread, but my report is set up with
    groups. So, when there are no records to print, my group header and group
    footer are still printed. What I'm after is to get the "No Records to
    Print" message on my report in this case.

    How can this be accomplished?

    Thanks.
  • edited July 2002
    When no records exist in your dataset, you need to set the
    Report.NoDataBehaviors property to [ndBlankPage].


    Cheers,

    Jim Bennett
    Digital Metaphors

  • edited July 2002
    That is the correct advide when the DataSet's RecordCount = 0, but there ARE
    records in my dataset, I'm just skipping through them, with the
    "NoDetailOnSkipRecords.zip" demo. My group header and footer are still
    printed in the case where there are records in my dataset, but according to
    my filter criteria, no records should be returned in the report.


  • edited July 2002
    Here is the code to do what you want. Basically, check for no data around
    the skipping logic, then disable all of the bands. To show the no data
    message: add a draw command to the page when all the records have been
    skipped as shown below:


    unit dm0116;

    interface

    uses
    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    StdCtrls, dmUtil, ppClass, ppBands, ppCache, ppCtrls, ppComm, ppReport,
    ppPrnabl, ppDB, ppDBBDE, Db, DBTables, ppStrtch, ppMemo, ppProd, ExtCtrls,
    ppDBPipe, ppVar, ppRelatv, Grids, DBGrids;

    type
    Tfrm0116 = class(TdmCustomForm)
    ppReport1: TppReport;
    ppReport1Header: TppHeaderBand;
    ppReport1Shape1: TppShape;
    ppReport1Label1: TppLabel;
    ppReport1Label2: TppLabel;
    ppReport1Label3: TppLabel;
    ppReport1Label4: TppLabel;
    ppReport1Label5: TppLabel;
    ppReport1Label6: TppLabel;
    ppReport1Detail: TppDetailBand;
    ppReport1Shape4: TppShape;
    ppReport1Shape5: TppShape;
    ppReport1Shape6: TppShape;
    ppReport1Shape3: TppShape;
    ppReport1Shape2: TppShape;
    ppReport1DBMemo1: TppDBMemo;
    ppReport1DBText1: TppDBText;
    ppReport1DBImage1: TppDBImage;
    ppReport1DBText2: TppDBText;
    ppReport1DBText3: TppDBText;
    ppReport1Footer: TppFooterBand;
    ppReport1Group1: TppGroup;
    ppReport1GroupHeader1: TppGroupHeaderBand;
    ppReport1GroupFooter1: TppGroupFooterBand;
    ppReport1Shape7: TppShape;
    ppReport1Label7: TppLabel;
    ppReport1DBCalc1: TppDBCalc;
    ppReport1Line1: TppLine;
    Table1: TTable;
    DataSource1: TDataSource;
    ppBDEPipeline1: TppBDEPipeline;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    RadioGroup1: TRadioGroup;
    Button1: TButton;
    ppReport1Calc1: TppSystemVariable;
    ppReport1Calc2: TppSystemVariable;
    Database1: TDatabase;
    DBGrid1: TDBGrid;
    procedure ppBDEPipeline1First(Sender: TObject);
    procedure ppBDEPipeline1Last(Sender: TObject);
    procedure ppBDEPipeline1Next(Sender: TObject);
    procedure ppBDEPipeline1Prior(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure ppReport1BeforePrint(Sender: TObject);
    procedure ppReport1HeaderBeforePrint(Sender: TObject);
    procedure ppReport1DetailBeforePrint(Sender: TObject);
    procedure ppReport1FooterBeforePrint(Sender: TObject);
    procedure ppReport1GroupFooter1BeforePrint(Sender: TObject);
    procedure ppReport1GroupHeader1BeforePrint(Sender: TObject);
    procedure ppReport1EndPage(Sender: TObject);
    private
    FNoData: Boolean;
    FSkipping: Boolean;

    procedure SkipBackward;
    procedure SkipForward;

    protected
    function GetReport: TppProducer; override;
    procedure Init; override;
    public
    { Public declarations }
    end;

    var
    frm0116: Tfrm0116;

    implementation

    {$R *.DFM}

    uses
    ppDevice, ppDrwCmd, ppTypes;

    procedure Tfrm0116.Init;
    begin
    AssignViewer := True;
    DisplayForm := True;
    end;

    function Tfrm0116.GetReport: TppProducer;
    begin
    Result := ppReport1;
    end;

    procedure Tfrm0116.Button1Click(Sender: TObject);
    begin
    {notify report that state of data has changed}
    ppReport1.Reset;

    {print the report}
    ppReport1.PrintToDevices;
    end;

    procedure Tfrm0116.SkipForward;
    var
    lbCheckForNoRecords: Boolean;
    begin

    if RadioGroup1.ItemIndex = 0 then Exit;

    if FSkipping then Exit;

    if Table1.EOF then Exit;

    FSkipping := True;

    if (ppdaFirstRecord in ppBDEPipeline1.State) then
    lbCheckForNoRecords := True
    else
    lbCheckForNoRecords := False;

    if RadioGroup1.ItemIndex = 1 then
    begin
    while not(Table1.EOF) and
    (Copy(Table1.FieldByName('Category').AsString, 1, 1) = 'S') do
    ppBDEPipeline1.Skip;
    end

    else if RadioGroup1.ItemIndex = 2 then
    begin
    while not(Table1.EOF) do
    ppBDEPipeline1.Skip;
    end;

    if lbCheckForNoRecords and (ppdaLastRecord in ppBDEPipeline1.State) then
    FNoData := True;

    FSkipping := False;
    end;

    procedure Tfrm0116.SkipBackward;
    begin
    if RadioGroup1.ItemIndex = 0 then Exit;

    if FSkipping then Exit;

    if Table1.BOF then Exit;

    FSkipping := True;

    while not(Table1.BOF) and (Copy(Table1.FieldByName('Category').AsString,
    1, 1) = 'S') do
    ppBDEPipeline1.SkipBack;

    FSkipping := False;

    end;

    procedure Tfrm0116.ppBDEPipeline1First(Sender: TObject);
    begin
    SkipForward;
    end;

    procedure Tfrm0116.ppBDEPipeline1Last(Sender: TObject);
    begin
    SkipBackward;
    end;

    procedure Tfrm0116.ppBDEPipeline1Next(Sender: TObject);
    begin
    SkipForward;
    end;

    procedure Tfrm0116.ppBDEPipeline1Prior(Sender: TObject);
    begin
    SkipBackward;
    end;

    procedure Tfrm0116.ppReport1BeforePrint(Sender: TObject);
    begin
    FNoData := False;
    end;

    procedure Tfrm0116.ppReport1HeaderBeforePrint(Sender: TObject);
    begin
    ppReport1Header.Visible := not(FNoData);
    end;

    procedure Tfrm0116.ppReport1DetailBeforePrint(Sender: TObject);
    begin
    ppReport1Detail.Visible := not(FNoData);
    end;

    procedure Tfrm0116.ppReport1FooterBeforePrint(Sender: TObject);
    begin
    ppReport1Footer.Visible := not(FNoData);
    end;

    procedure Tfrm0116.ppReport1GroupFooter1BeforePrint(Sender: TObject);
    begin
    ppReport1GroupFooter1.Visible := not(FNoData);
    end;

    procedure Tfrm0116.ppReport1GroupHeader1BeforePrint(Sender: TObject);
    begin
    ppReport1GroupHeader1.Visible := not(FNoData);
    end;

    procedure Tfrm0116.ppReport1EndPage(Sender: TObject);
    var
    lPage: TppPage;
    lDrawText: TppDrawText;
    begin

    if FNoData then
    begin
    lPage := ppReport1.Engine.Page;

    lDrawText := TppDrawText.Create(lPage);
    lDrawText.Top := ppReport1.PrinterSetup.PageDef.mmPrintableHeight div
    2;
    lDrawText.Left := ppReport1.PrinterSetup.PageDef.mmPrintableWidth div
    2;
    lDrawText.Text := 'NO DATA';
    lDrawText.Width := 50800;
    lDrawText.Height := 12700;
    lDrawText.Font.Color := clBlack;
    lDrawText.Font.Size := 18;
    lDrawText.Font.Name := 'Arial';
    lDrawText.Page := lPage;
    end;

    end;

    end.


    Cheers,

    Jim Bennett
    Digital Metaphors

This discussion has been closed.