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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
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; |