设为首页 加入收藏

TOP

【转】FastReport经验(四)
2017-10-10 12:06:03 】 浏览:10432
Tags:FastReport 经验
reReport do
begin
if (Frx.Engine.TotalPages<=1) then Break;
R:=Pelstomm(Frx.Engine.TotalPages*Frx.Engine.PageHeight-
Frx.Engine.FreeSpace)+R1;
P:=TfrxReportPage(Frx.Pages[SequencePage]);
P.PaperHeight:=R;
end;
{必须用上面的循环代码来得到准确的空白区域
不能用通过计算总页数减去各页的页边距的方法来获得空白区域
因为如果碰到一条记录过宽的情况导致换页,就不准确了。}
R:=Pelstomm(Frx.Engine.TotalPages*Frx.Engine.PageHeight-
Frx.Engine.FreeSpace)+R1;
P:=TfrxReportPage(Frx.Pages[SequencePage]);
P.PaperHeight:=R;
end;

在预览或打印前先调用PrintSerial即可。

12.如何在程序中指定打印机名称?
frxReport1.Report.PrintOptions.Printer := ‘打印机名称’;

13.如何使用打印机直接打印?
implementation
uses Printers;
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
Printer.PrinterIndex := 0;{网络打印机也是要安装在你本地的操作系统中的,直接使用顺序

试试吧}
Printers.Printer.SetPrinter(’HP1020′,’HP1020′,’LPT1′,0);{打印机名字,驱动,端口等,

自查,我是用虚拟打印机测试的}

Printers.Printer.BeginDoc;
Printers.Printer.Canvas.TextOut(10,10,’打印这一行字’);
Printers.Printer.EndDoc;
end;

14.如何打印空白处?
在打印报表的Band处的OnBeforePrint事件中添加代码:
while FreeSpace > 20 do
ShowBand(Child1)

15.如何打印指定行数后换页?
在master band中OnBeforePrint事件中写代码:
var
vLineCount: integer;
begin
vLineCount := vLineCount + 1;
if vLineCount = 10 then
begin
vLineCount := 0;
NewPage;
end;
end;

16.fastreport中如何把数据显示为百分比
DisplayFormat属性,其中的Kind你设置成fkNumeric,FormatStr
[<frxDBDataset1."sjl">*100 #n%2.2f]%”。

17.FastReport如何打印表格式的空行?
var
PageLine: integer;       //在現在頁列印到第幾行
PageMaxRow: integer=15;  //設定每頁列數
procedure MasterData1OnBeforePrint(Sender: TfrxComponent);
begin
PageLine := <Line> mod PageMaxRow;
if (PageLine = 1) and (<line> > 1) then
Engine.newpage;
child1.visible := False;
end;

//Footer1高度設為0
procedure Footer1OnBeforePrint(Sender: TfrxComponent);

var
i: integer;
begin
i := iif(PageLine=0, PageMaxRow, PageLine);
child1.visible := True;
while i < PageMaxRow do
begin
i := i + 1;
Engine.ShowBand(Child1);  //印空白表格
end;
child1.visible := False;
end;
begin
end.

========================================================================
早期版本

—————- 使用自定义函数 —————————————-

Q: 我怎样添加我的自定义函数?
A: 使用 TfrReport.OnUserFunction 事件. 这里有一个简单的例子:

procedure TForm1.frReport1UserFunction(const Name: String;
p1, p2, p3: Variant; var val: Variant);
begin
if AnsiCompareText(’SUMTOSTR’, Name) = 0 then
val := My_Convertion_Routine(frParser.Calc(p1));
end;

然后,你就可以在报表(任何表达式或脚本)的任何地方使用 SumToStr 函数了。

Q: 但是它仅仅能工作在一个TfrReport组件中。可我想在任何地方(在所有的TfrReport组件中)

使用的我的自定义函数?
A: 使 OnUserFunction event 句柄作为所有组件的公用句柄。如果你不能做到这一点,你需要创

建函数库:

type
TMyFunctionLibrary = class(TfrFunctionLibrary)
public
constructor Create; override;
procedure DoFunction(Fno: Integer; p1, p2, p3: Variant;
var val: Variant); override;
end;

constructor TMyFunctionLibrary.Create;
begin
inherited Create;
with List do
begin
Add(’DATETOSTR’);
Add(’SUMTOSTR’);
end;
end;

procedure TMyFunctionLibrary.DoFunction(Fno: Integer; p1, p2, p3: Variant;
var val: Variant);
begin
val := 0;
case Fno of
0: val := My_DateConvertion_Routine(frParser.Calc(p1));
1: val := My_SumConvertion_Routine(frParser.Calc(p1));
end;
end;

要注册函数库,调用
frRegisterFunctionLibrary(TMyFunctionLibrary);
要卸载函数库,调用
frUnRegisterFunctionLibrary(TMyFunctionLibrary);

Q: 我怎样将我的函数添加到函数列表中 (用表达式生成器)?
A: 使用 frAddFunctionDesc 过程 (在FR_Class 单元中):

frAddFunctionDesc(FuncLib, ‘SUM

首页 上一页 1 2 3 4 5 6 下一页 尾页 4/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇HO引擎近况20160710 下一篇[教学] 将 Form 内的控件变成 Sty..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目