delphi中使用fastreport制作动态报表的问题,请帮帮忙? ( 积分: 50 )

  • 主题发起人 主题发起人 zfjy2k
  • 开始时间 开始时间
Z

zfjy2k

Unregistered / Unconfirmed
GUEST, unregistred user!
我开发环境是delphi7+fastreport 3.05。我打算做了一个这样程序,首先把一个数据表中的所有字段名列在一个多选框中,然后用户通过选择多选框的字段名来自动生成一个报表,也就是要制作一个动态报表。下面我程序的代码:
  我在程序窗体内放了一个frxReport1、一个database、一个table、一个按钮。
  procedure TForm1.Button1Click(Sender: TObject);
var
v: TfrView;
b: TfrBandView;
Page: TfrPage;
begin
frReport1.Pages.Clear;
frReport1.Pages.Add;
// create page
Page := frReport1.Pages[0];
b := TfrBandView(frCreateObject(gtBand, ''));
// create MasterData band
b.SetBounds(0, 20, 0, 20);
// position and size in pixels
b.BandType := btMasterData;
b.Dataset := 'frDBDataSet1';
// reference to band dataset
Page.Objects.Add(b);
v := frCreateObject(gtMemo, '');
// create data field
v.SetBounds(20, 20, 200, 16);
v.Memo.Add('[Table1."name"]');
Page.Objects.Add(v);
frReport1.ShowReport;
end;

程序运行后报以下错误:
[Error] Unit1.pas(32): Undeclared identifier: 'TfrView'
[Error] Unit1.pas(33): Undeclared identifier: 'TfrBandView'
[Error] Unit1.pas(34): Undeclared identifier: 'TfrPage'
[Error] Unit1.pas(36): Undeclared identifier: 'frReport1'
[Error] Unit1.pas(36): Missing operator or semicolon
[Error] Unit1.pas(37): Missing operator or semicolon
[Error] Unit1.pas(38): Missing operator or semicolon
[Error] Unit1.pas(40): Undeclared identifier: 'frCreateObject'
[Error] Unit1.pas(40): Undeclared identifier: 'gtBand'
[Error] Unit1.pas(41): Missing operator or semicolon
[Error] Unit1.pas(42): Missing operator or semicolon
[Error] Unit1.pas(42): Undeclared identifier: 'btMasterData'
[Error] Unit1.pas(43): Missing operator or semicolon
[Error] Unit1.pas(44): Missing operator or semicolon
[Error] Unit1.pas(46): Undeclared identifier: 'gtMemo'
[Error] Unit1.pas(47): Missing operator or semicolon
[Error] Unit1.pas(48): Missing operator or semicolon
[Error] Unit1.pas(49): Missing operator or semicolon
[Error] Unit1.pas(51): Missing operator or semicolon
[Error] Unit1.pas(59): Undeclared identifier: 'Sender'
[Error] Unit1.pas(59): Undeclared identifier: 'btReportTitle'
[Error] Unit1.pas(62): Missing operator or semicolon
[Error] Unit1.pas(64): Missing operator or semicolon
[Error] Unit1.pas(66): Missing operator or semicolon
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
请问这是怎么回事?我是不是还有哪个单元没有引用?请帮帮我,谢谢!
 
我开发环境是delphi7+fastreport 3.05。我打算做了一个这样程序,首先把一个数据表中的所有字段名列在一个多选框中,然后用户通过选择多选框的字段名来自动生成一个报表,也就是要制作一个动态报表。下面我程序的代码:
  我在程序窗体内放了一个frxReport1、一个database、一个table、一个按钮。
  procedure TForm1.Button1Click(Sender: TObject);
var
v: TfrView;
b: TfrBandView;
Page: TfrPage;
begin
frReport1.Pages.Clear;
frReport1.Pages.Add;
// create page
Page := frReport1.Pages[0];
b := TfrBandView(frCreateObject(gtBand, ''));
// create MasterData band
b.SetBounds(0, 20, 0, 20);
// position and size in pixels
b.BandType := btMasterData;
b.Dataset := 'frDBDataSet1';
// reference to band dataset
Page.Objects.Add(b);
v := frCreateObject(gtMemo, '');
// create data field
v.SetBounds(20, 20, 200, 16);
v.Memo.Add('[Table1."name"]');
Page.Objects.Add(v);
frReport1.ShowReport;
end;

程序运行后报以下错误:
[Error] Unit1.pas(32): Undeclared identifier: 'TfrView'
[Error] Unit1.pas(33): Undeclared identifier: 'TfrBandView'
[Error] Unit1.pas(34): Undeclared identifier: 'TfrPage'
[Error] Unit1.pas(36): Undeclared identifier: 'frReport1'
[Error] Unit1.pas(36): Missing operator or semicolon
[Error] Unit1.pas(37): Missing operator or semicolon
[Error] Unit1.pas(38): Missing operator or semicolon
[Error] Unit1.pas(40): Undeclared identifier: 'frCreateObject'
[Error] Unit1.pas(40): Undeclared identifier: 'gtBand'
[Error] Unit1.pas(41): Missing operator or semicolon
[Error] Unit1.pas(42): Missing operator or semicolon
[Error] Unit1.pas(42): Undeclared identifier: 'btMasterData'
[Error] Unit1.pas(43): Missing operator or semicolon
[Error] Unit1.pas(44): Missing operator or semicolon
[Error] Unit1.pas(46): Undeclared identifier: 'gtMemo'
[Error] Unit1.pas(47): Missing operator or semicolon
[Error] Unit1.pas(48): Missing operator or semicolon
[Error] Unit1.pas(49): Missing operator or semicolon
[Error] Unit1.pas(51): Missing operator or semicolon
[Error] Unit1.pas(59): Undeclared identifier: 'Sender'
[Error] Unit1.pas(59): Undeclared identifier: 'btReportTitle'
[Error] Unit1.pas(62): Missing operator or semicolon
[Error] Unit1.pas(64): Missing operator or semicolon
[Error] Unit1.pas(66): Missing operator or semicolon
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
请问这是怎么回事?我是不是还有哪个单元没有引用?请帮帮我,谢谢!
 
是不是frview单元?
 
不是,use frview单元后,提示:
[Fatal Error] Unit1.pas(7): File not found: 'frview.dcu'
 
程序默认的引用单元有这些:
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBTables, StdCtrls, frxClass;
 
我把所有引用都还不行
uses
frxDesgn, frxClass, frxDCtrl, frxChart, frxRich, frxBarcode, ImgList, ComCtrls, ExtCtrls, frxOLE, frxCross, frxDMPExport, frxExportImage, frxExportRTF, frxExportTXT, frxExportXML, frxExportXLS, frxExportHTML, frxGZip, frxExportPDF, frxBDEComponents, frxDBSet;
 
你上面那个例子是FR的例子,不能在FR3中使用,你可以改一下就可以了
 
怎么改?改哪里呢?
 
还有人知道吗?谢谢!
 
这个是fr3自带的例子,可以参考一下:
var
Page: TfrxReportPage;
Band: TfrxBand;
DataBand: TfrxMasterData;
Memo: TfrxMemoView;
{ clear a report }
frxReport1.Clear;
{ add a dataset to the list of ones accessible for a report }
frxReport1.DataSets.Add(frxDBDataSet1);
{ add a page }
Page := TfrxReportPage.Create(frxReport1);
{ create a unique name }
Page.CreateUniqueName;
{ set sizes of fields, paper and orientation by default }
Page.SetDefaults;
{ modify paper’s orientation }
Page.Orientation := poLandscape;
{ add a report title band}
Band := TfrxReportTitle.Create(Page);
Band.CreateUniqueName;
{ it is sufficient to set the «Top»
coordinate and height for a band }
{ both coordinates are in pixels }
Band.Top := 0;
Band.Height := 20;
{ add an object to the report title band }
Memo := TfrxMemoView.Create(Band);
Memo.CreateUniqueName;
Memo.Text := 'Hello FastReport!';
Memo.Height := 20;
{ this object will be stretched according to band’s width }
Memo.Align := baWidth;
{ add the masterdata band }
DataBand := TfrxMasterData.Create(Page);
DataBand.CreateUniqueName;
DataBand.DataSet := frxDBDataSet1;
{ the Top coordinate should be greater than the previously added band’s
top + height}
DataBand.Top := 100;
DataBand.Height := 20;
{ add an object on master data }
Memo := TfrxMemoView.Create(DataBand);
Memo.CreateUniqueName;
{ connect to data }
Memo.DataSet := frxDBDataSet1;
Memo.DataField := 'CustNo';
Memo.SetBounds(0, 0, 100, 20);
{ adjust the text to the right object’s margin }
Memo.HAlign := haRight;
{ show the report }
frxReport1.ShowReport;
 
这个例子运行会报错,错误如下:
 这条语句Page.Orientation := poLandscape;报下面错误
  [Error] Unit1.pas(46): Undeclared identifier: 'poLandscape'
 
多人接受答案了。
 
后退
顶部