如何从TStringGrid的内容创建QuickReport [英] How to create a QuickReport from the contents of a TStringGrid

查看:85
本文介绍了如何从TStringGrid的内容创建QuickReport的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 7上使用Delphi 7和QuickReports。通常,QuickReports需要由查询生成的数据集,但是我想从StringGrid的内容中生成报告,就像StringGrid代表了结果的表述一样。查询。

I'm using Delphi 7 and QuickReports on Windows 7. Normally QuickReports require a DataSet generated by a query, but I want to make a report from the contents of a StringGrid as though the StringGrid is a representation of the results of a query.

如何?

推荐答案

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

Use the QuickReport.OnNeedData event handler. It passes a var parameter called MoreData (a boolean); setting it to True means it gets called again. Leave the QuickReport.DataSource property blank, and use plain TQRText controls rather than 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;

这篇关于如何从TStringGrid的内容创建QuickReport的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆