Grid++Report安装到Lazarus后,Grid++Report的查询显示器,打印预览器,报表主对象和报表设计器的的相关命令要通过OleServer来具体调用。除此之外,使用方法与在Delphi中没有区别。
如:
AxcGridppReport1.OleServer.LoadFromFile('d:\1.grf'); //读入一个报表模板 ,中间加了OleServer
Form1的lfm文件:
object Form1: TForm1
Left = 234
Height = 421
Top = 134
Width = 633
Caption = 'Form1'
ClientHeight = 421
ClientWidth = 633
OnShow = FormShow
LCLVersion = '1.0.10.0'
WindowState = wsMaximized
object AxcGRDisplayViewer1: TAxcGRDisplayViewer
Left = 0
Height = 365
Top = 56
Width = 633
Align = alClient
AutoSize = True
TabOrder = 0
UseDockManager = False
Active = False
OnContentCellDblClick = AxcGRDisplayViewer1ContentCellDblClick
end
object AxcGridppReport1: TAxcGridppReport
Left = 200
Height = 24
Top = 8
Width = 24
TabOrder = 1
UseDockManager = False
Active = False
OnExportEnd = AxcGridppReport1ExportEnd
end
object Panel1: TPanel
Left = 0
Height = 56
Top = 0
Width = 633
Align = alTop
ClientHeight = 56
ClientWidth = 633
TabOrder = 2
object Button1: TButton
Left = 24
Height = 25
Top = 8
Width = 115
Caption = '展示报表'
OnClick = Button1Click
TabOrder = 0
end
object Button2: TButton
Left = 160
Height = 25
Top = 8
Width = 107
Caption = '设计报表'
TabOrder = 1
Visible = False
end
end
end
Unit单元文件:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, grproLib_5_0_TLB, RTTICtrls, RTTIGrids, Forms,
Controls, Graphics, Dialogs, StdCtrls, ExtCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
AxcGRDisplayViewer1: TAxcGRDisplayViewer;
AxcGridppReport1: TAxcGridppReport;
Button1: TButton;
Button2: TButton;
Panel1: TPanel;
procedure AxcGRDisplayViewer1ContentCellDblClick(Sender: TObject;
pSender: IGRColumnContentCell);
procedure AxcGridppReport1ExportEnd(Sender: TObject;
pOptionObject: IGRExportOption);
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormShow(Sender: TObject);
begin
AxcGRDisplayViewer1.Active:=true;
//激活报表COM组件,带有界面的Com组件要执行本命令才会显示在Form中
end;
procedure TForm1.AxcGridppReport1ExportEnd(Sender: TObject;
pOptionObject: IGRExportOption);
begin
self.Caption:='导出数据成功'; //测试主报表事件是否生效
end;
procedure TForm1.AxcGRDisplayViewer1ContentCellDblClick(Sender: TObject;
pSender: IGRColumnContentCell);
begin
ShowMessage(pSender.DataField);
//报表查询显示器内容格双击事件中取出内容格关联的字段名称
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if AxcGRDisplayViewer1.OleServer.Running then AxcGRDisplayViewer1.OleServer.Stop;
AxcGRDisplayViewer1.OleServer.ShowToolbar:=true; //显示报表工具条
AxcGridppReport1.OleServer.LoadFromFile('d:\1.grf'); //读入一个报表模板
AxcGRDisplayViewer1.OleServer.Report := AxcGridppReport1.OleServer;//报表关联到AxcGRDisplayViewe(查询显示器控件)
AxcGRDisplayViewer1.OleServer.Start; //启动报表
end;
end.
附一个运行效果图片: