How To…Check For Data Before Printing

Question

“How do I check if there is data to be retrieved before printing my report?”

Solution

Check the TppDataPipeline.EOF and TppDataPipeline.BOF properties.  If both of these properties are True, the dataset contains no data.  Note that the datapipeline will need to be opened to successfully access these properties.

Download:  CheckForDataBeforePrinting.zip

Sample Delphi code:

function TForm1.HaveData: Boolean;
begin

  try

    TQuery(TppDBPipeline(ppReport1.DataPipeline).DataSource.DataSet).AfterOpen := AfterOpenEvent;

    TdaQueryDataView(ppReport1.DataPipeline.DataView).Active := True;

    //Open the datapipeline/dataset.
    ppReport1.DataPipeline.Open;

    TppDBPipeline(ppReport1.DataPipeline).OpenDatasource := False;

    //Check for no data.
    if (ppReport1.DataPipeline.BOF and ppReport1.DataPipeline.EOF) then
      Result := False
    else
      Result := True;

  except
    Result:=False;
  end;

end;