编码中对fastreport 设计组件的访问

    技术2022-05-11  86

            使用FastReport制作报表的时候,不想过去使用QuickRep,用到的文本框、BAND不能在窗口文件(.pas)中显式的看到,那么,怎样才能在程序中访问到这些组件以及操作他们的成员属性和方法呢?

            其实,FastReport的设计组件一般都是从TfrView类继承而来的,如文本框(TfrMemoView)、BAND(TfrBandView)等,所以,TfrReport类也提供了访问这些组件的方法FindObject,其原型如下: 

            function TfrReport.FindObject(Name: string): TfrView;

            下面以例子的方式,给出其用法:

            我们在一个项目中,新建了一个窗口名为Form1,在其上放置一个报表控件frReport1,设计时放置一个ReportTitle1,和一个文本框组件Memo1,那么在程序中访问这些组件的方法如下:      

    unit Unit1;

    interface

    uses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls, FR_Class;

    type  TForm1 = class(TForm)    frReport1: TfrReport;    Button1: TButton;    procedure Button1Click(Sender: TObject);  private    { Private declarations }  public    { Public declarations }  end;

    var  Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);var i: integer;    v: TfrBandView;begin  v := TfrBandView(self.frReport1.FindObject('ReportTitle1'));  if v <> nil then begin    //在此加入访问和操作ReportTitle1的代码  end;end;

    end.


    最新回复(0)