在Fast Report VCL(Delphi)中创建和删除对象
我使用FastReport4来显示一些动态生成的数据,并在报告中重新排列 我在报告中使用“模板”对象来获得初始位置(在我的实际程序中,我复制字体属性、对齐方式等) 我已经设法创建了一个小项目,这样我就可以在报表中创建一个备忘录组件,预览报表,然后删除该组件,这样我就可以使用不同的数据重用报表 但是,当我释放创建的对象时,我会丢失报告中的其他对象(在本例中,我的模板对象在第二次预览报告时找不到) 从快速报告中创建和删除对象的正确方法是什么 这是帕斯卡单位:在Fast Report VCL(Delphi)中创建和删除对象,delphi,fastreport,Delphi,Fastreport,我使用FastReport4来显示一些动态生成的数据,并在报告中重新排列 我在报告中使用“模板”对象来获得初始位置(在我的实际程序中,我复制字体属性、对齐方式等) 我已经设法创建了一个小项目,这样我就可以在报表中创建一个备忘录组件,预览报表,然后删除该组件,这样我就可以使用不同的数据重用报表 但是,当我释放创建的对象时,我会丢失报告中的其他对象(在本例中,我的模板对象在第二次预览报告时找不到) 从快速报告中创建和删除对象的正确方法是什么 这是帕斯卡单位: unit Unit1; interfa
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, frxClass;
type
TForm1 = class(TForm)
frxReport1: TfrxReport;
btn1: TButton;
procedure btn1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
var
modelObj: TfrxComponent;
newObj: TfrxMemoView;
begin
modelObj := frxReport1.FindObject('modelObj');
newObj := TfrxMemoView.Create(modelObj.Parent);
newObj.CreateUniqueName;
newObj.Text := 'Whee';
newObj.SetBounds(modelObj.Left, modelObj.Top + modelObj.Height,
modelObj.Width, modelObj.Height);
frxReport1.PrepareReport;
frxReport1.ShowPreparedReport;
newObj.Free;
end;
end.
以下是DFM:
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 299
ClientWidth = 635
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object btn1: TButton
Left = 224
Top = 48
Width = 75
Height = 25
Caption = 'btn1'
TabOrder = 0
OnClick = btn1Click
end
object frxReport1: TfrxReport
Version = '4.15'
DotMatrixReport = False
IniFile = '\Software\Fast Reports'
PreviewOptions.Buttons = [pbPrint, pbLoad, pbSave, pbExport, pbZoom, pbFind, pbOutline, pbPageSetup, pbTools, pbEdit, pbNavigator, pbExportQuick]
PreviewOptions.Zoom = 1.000000000000000000
PrintOptions.Printer = 'Por defecto'
PrintOptions.PrintOnSheet = 0
ReportOptions.CreateDate = 41905.757295162040000000
ReportOptions.LastChange = 41905.757295162040000000
ScriptLanguage = 'PascalScript'
ScriptText.Strings = (
'begin'
''
'end.')
Left = 72
Top = 32
Datasets = <>
Variables = <>
Style = <>
object Data: TfrxDataPage
Height = 1000.000000000000000000
Width = 1000.000000000000000000
end
object Page1: TfrxReportPage
PaperWidth = 216.000000000000000000
PaperHeight = 279.000000000000000000
PaperSize = 1
LeftMargin = 10.000000000000000000
RightMargin = 10.000000000000000000
TopMargin = 10.000000000000000000
BottomMargin = 10.000000000000000000
object PageHeader1: TfrxPageHeader
Height = 279.685220000000000000
Top = 18.897650000000000000
Width = 740.787880000000000000
object modelObj: TfrxMemoView
Left = 166.299320000000000000
Top = 30.236240000000000000
Width = 264.567100000000000000
Height = 18.897650000000000000
ShowHint = False
Color = clYellow
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Height = -13
Font.Name = 'Arial'
Font.Style = []
Memo.UTF8W = (
'Model')
ParentFont = False
end
end
end
end
end
对象格式1:t格式1
左=0
Top=0
标题='Form1'
ClientHeight=299
ClientWidth=635
颜色=clBtnFace
Font.Charset=默认字符集
Font.Color=clWindowText
字体高度=-11
Font.Name='Tahoma'
Font.Style=[]
OldCreateOrder=False
PixelsPerInch=96
text高度=13
对象btn1:TButton
左=224
Top=48
宽度=75
高度=25
标题='btn1'
TabOrder=0
OnClick=btn1Click
结束
对象frxReport1:TfrxReport
版本='4.15'
DotMatrixReport=False
IniFile='\Software\Fast Reports'
预览选项。按钮=[pbPrint、pbLoad、pbSave、pbExport、pbZoom、pbFind、pbOutline、pbPageSetup、pbTools、pbEdit、pbNavigator、pbExportQuick]
预览选项。缩放=1.000000000000000000000000
PrintOptions.Printer='Por defecto'
PrintOptions.PrintOnSheet=0
ReportOptions.CreateDate=41905.75729516204000000
ReportOptions.LastChange=41905.75729516204000000
ScriptLanguage='PascalScript'
ScriptText.String=(
“开始”
''
“结束。”)
左=72
Top=32
数据集=
变量=
样式=
对象数据:TfrxDataPage
高度=1000.000000000000000000000000
宽度=1000.000000000000000000000000
结束
对象页面1:TfrxReportPage
纸张宽度=216.000000000000000000000000
纸张高度=279.000000000000000000000000
纸张尺寸=1
LeftMargin=10.000000000000000000
RightMargin=10.000000000000000000000000
TopMargin=10.000000000000000000000000
底部保证金=10.000000000000000000000000
对象PageHeader1:TfrxPageHeader
高度=279.68522000000000
Top=18.897650000000000000
宽度=740.7878800000000000
对象模型obj:TfrxMemoView
左=166.299320000000000
Top=30.236240000000000000
宽度=264.567100000000
高度=18.897650000000000000
ShowHint=False
颜色=黄色
Font.Charset=默认字符集
Font.Color=clBlack
字体高度=-13
Font.Name='Arial'
Font.Style=[]
Memo.UTF8W=(
"模型")
ParentFont=False
结束
结束
结束
结束
结束
对不起,我的第一个回答有误导性。它看起来像PrepareReport中的一个内部错误,对象似乎是交换的
var
modelObj: TfrxComponent;
newObj: TfrxMemoView;
cn:String;
begin
modelObj := frxReport1.FindObject('modelObj');
newObj := TfrxMemoView.Create(modelObj.Parent);
newObj.CreateUniqueName;
cn := newObj.Name; // keep for dirty workaround
newObj.Text := 'Whee';
newObj.SetBounds(modelObj.Left, modelObj.Top + modelObj.Height,
modelObj.Width, modelObj.Height);
Showmessage('New: ' + newObj.Name + ' modelObj: ' + modelObj.Name);
frxReport1.PrepareReport;
Showmessage('New: ' + newObj.Name + ' modelObj: ' + modelObj.Name);
frxReport1.ShowPreparedReport;
newObj := TfrxMemoView(frxReport1.FindObject(cn)); // dirty workaround
newObj.Free;
end;
输出:
New: Memo1 modelObj: modelObj
New: modelObj modelObj: Memo1
此处显示的解决方法将不是一种可用的方法,因此从文件加载报告或将TfrxReport组件放置在数据模块上(打印前创建,打印后销毁)可能是更好的解决方法,直到修复此错误。Aha,因此它是一个错误。作为一种解决方法,我正在创建一个新报告,并使用
NewReport.AssignAll(BaseReport)
从原始报告复制。这似乎奏效了。