如何从TStringGrid的内容创建QuickReport

Sam*_*Sam 1 delphi quickreports

我在Windows 7上使用Delphi 7和QuickReports.通常,QuickReports需要查询生成的DataSet,但我想从StringGrid的内容生成报告,就像StringGrid是查询结果的表示一样.

怎么样?

Ken*_*ite 6

使用QuickReport.OnNeedData事件处理程序.它传递一个名为MoreData(一个布尔值)的var参数; 将其设置为True意味着它再次被调用.将QuickReport.DataSource属性保留为空,并使用普通的TQRText控件而不是TQRDBText.

// CurrLine is an Integer. In your case, it can represent a row in the StringGrid.
procedure TPrintLogForm.QuickRep1NeedData(Sender: TObject;
                      var MoreData: Boolean);
begin
  MoreData := (CurrLine < StringGrid1.RowCount);
  if MoreData then
  begin
    qrTextLine.Caption := StringGrid1.Cells[0, CurrLine];
    qrTextData.Caption := StringGrid1.Cells[1, CurrLine];
    Inc(CurrLine);
  end;
end;
Run Code Online (Sandbox Code Playgroud)