上一篇向大家介绍了建立一张简单报表的过程。这篇文章向大家介绍rave报表代码编程实例。窗体上放置组件:RvSystem, Button即可。
具体代码如下:
##################################################################################
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, RpDefine, RpBase, RpSystem;
type
TForm1 = class(TForm)
RvSystem1: TRvSystem;
Button1: TButton;
procedure RvSystem1Print(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.RvSystem1Print(Sender: TObject);
var
I1: integer;
S1: string[20];
S2: string[20];
Bitmap: TBitmap;
PolyLineArr: array[1..6] of TPoint;
begin
with Sender as TBaseReport do begin
{ 打印表头和表尾 }
SectionTop := 0.75; //顶端
SetFont('黑体',26); //设置字体
Underline := true; //下划线
Home;
YPos := 1.0;
FontRotation :=20;//旋转角度
PrintCenter('我的报表',PageWidth / 2);
SetFont('宋体',10);
SectionBottom := 10.75;
PrintFooter(' 第' + IntToStr(CurrentPage) + '页',pjLeft); //页码
PrintFooter('日期: '+DateToStr(Date)+' ',pjRight); //日期
SectionBottom := 10.5;
YPos := 1.5;
SetFont('宋体',12);
SetTopOfPage;
Home;
{ 打印列标题 }
ClearTabs;
SetPen(clBlack,psSolid,1,pmCopy); { 设置画笔为一个点宽 }
SetTab(0.5,pjCenter,3.5,0,BOXLINEALL,0);
SetTab(NA,pjCenter,1.0,0,BOXLINEALL,0);
SetTab(NA,pjCenter,1.5,0,BOXLINEALL,0);
SetTab(NA,pjCenter,1.5,0,BOXLINEALL,0);
Bold := true;
Tab(-2,NA,-2,-2,NA); { 画出具有粗边框的表格 }
Print('Name');
Tab(NA,NA,-2,-2,NA);
Print('Number');
Tab(NA,NA,-2,-2,NA);
Print('Amount 1');
Tab(NA,-2,-2,-2,NA);
Println('Amount 2');
Bold := false;
{ 打印具有边框的数据 }
ClearTabs;
SetTab(0.5,pjLeft,3.5,2,BOXLINEALL,0);
SetTab(NA,pjCenter,1.0,2,BOXLINEALL,0);
SetTab(NA,pjRight,1.5,2,BOXLINEALL,10);
SetTab(NA,pjRight,1.5,2,BOXLINEALL,0);
for I1 := 1 to 10 do begin
Str(I1 * 1.23:2:2,S1);
Str(I1 * 98.76:2:2,S2);
Print(#9'LastName' + IntToStr(I1) + ', ');
SetFont('Times New Roman',8);
Print('FirstName M.');
SetFont('Times New Roman',12);
Println(#9 + IntToStr(I1) + #9'$' + S1 + #9'$' + S2);
end; { for }
{ 打印具有阴影的数据 }
ClearTabs;
SetTab(0.5,pjLeft,3.5,2,BOXLINENONE,0);
SetTab(NA,pjCenter,1.0,2,BOXLINENONE,0);
SetTab(NA,pjRight,1.5,2,BOXLINENONE,0);
SetTab(NA,pjRight,1.5,2,BOXLINENONE,0);
for I1 := 11 to 20 do begin
If Odd(I1) then begin
TabShade := 0;
end else begin
TabShade := 15;
end; { else }
Str(I1 * 1.23:2:2,S1);
Str(I1 * 98.76:2:2,S2);
Print(#9'LastName' + IntToStr(I1) + ', ');
SetFont('Times New Roman',8);
Print('FirstName M.');
SetFont('Times New Roman',12);
Println(#9 + IntToStr(I1) + #9'$' + S1 + #9'$' + S2);
end; { for }
ClearTabs;
{ 分栏报表 }
ClearTabs;
SetTopOfPage;
SectionBottom := 8.0;
Home;
SetFont('宋体',12);
Bold := true;
Underline := true;
Print(' 分栏报表 (LinesLeft/ColumnLinesLeft/LineNum/ColumnNum)');
SetTopOfPage; { Set top of page to current YPos }
Bold := false;
Underline := false;
Italic := false;
Home; { Goto home position }
SetColumns(4,0.5); { Create 4 columns with 0.5" between each }
while ColumnLinesLeft > 0 do begin
Println(IntToStr(LinesLeft) + '/' + IntToStr(ColumnLinesLeft) + '/' +
IntToStr(LineNum) + '/' + IntToStr(ColumnNum));
end; { while }
{ 具有边框的分栏报表 }
ClearTabs;
SetTopOfPage;
SectionBottom := 10.5;
Home;
SetFont('Times New Roman',12);
Bold := true;
Italic := true;
Print('Boxed Columns');
SetTopOfPage; { Set top of page to current YPos }
Bold := false;
Italic := false;
Home; { Goto home position }
ClearTabs;
SetPen(clBlack,psSolid,1,pmCopy);
SetTab(0.5,pjCenter,0.375,0,BOXLINEALL,0);
SetTab(NA,pjCenter,0.375,0,BOXLINEALL,0);
SetTab(NA,pjCenter,0.375,0,BOXLINEALL,0);
SetTab(NA,pjCenter,0.375,0,BOXLINEALL,0);
SetColumns(4,0.5); { Create 4 columns with 0.5" between each }
while ColumnLinesLeft > 0 do begin
if LineNum = 1 then begin
TabShade := 15;
Println(#9'LL'#9'CLL'#9'L#'#9'C#'); { 打印标题栏 }
end else begin
TabShade := 0;
Println(#9 + IntToStr(LinesLeft) + #9 + IntToStr(ColumnLinesLeft) +
#9 + IntToStr(LineNum) + #9 + IntToStr(ColumnNum));
end; { else }
end; { while }
SetColumns(1,0);
{ 在指定位置绘出文本 }
NewPage;
OriginX := 0.0; { Set origin to normal }
OriginY := 0.0;
GotoXY(1.0,1.5);
Print('Text @ 1.0,1.5');
GotoXY(6.0,1.5);
Println('Text @ 6.0,1.5');
GotoXY(2.0,2.0);
Println('Text @ 2.0,2.0');
GotoXY(3.0,2.5);
Println('Text @ 3.0,2.5');
{*** 图形 图片***}
NewPage;
ResetSection;
SetFont('Arial',24);
Underline := true;
Home;
PrintCenter('Graphics Page Demo',PageWidth / 2);
SetFont('Times New Roman',8);
SectionBottom := 10.75; { Temporarily move the section bottom down }
PrintFooter('Page ' + IntToStr(CurrentPage),pjLeft);
PrintFooter('Date 01/20/95',pjRight);
SectionBottom := 10.5; { Reset section bottom }
OriginX := 0.0;
OriginY := 0.5;
SetFont('Arial',10);
{ 半圆 弧线}
SetPen(clBlack,psSolid,-2,pmCopy); { Set pen to black 2/100ths" wide }
YPos := 0.95;
PrintCenter('Arc() and Chord()',2.125);
Arc(1.125,1.0,3.125,3.0,3.125,2.0,0.0,0.0);
SetBrush(clBlack,bsClear,nil);
Chord(1.125,1.0,3.125,3.0,0.0,0.8,3.125,2.25);
{ 饼图 }
YPos := 0.95;
PrintCenter('Pie()',4.25);
SetPen(clBlack,psSolid,-2,pmCopy); { Set pen to black 2/100ths" wide }
SetBrush(clBlack,bsHorizontal,nil);
Pie(3.25,1.0,5.25,3.0,5.25,2.0,0.0,0.0);
SetBrush(clBlack,bsVertical,nil);
Pie(3.25,1.0,5.25,3.0,0.0,0.0,3.25,7.0);
SetBrush(clBlack,bsBDiagonal,nil);
Pie(3.25,1.0,5.25,3.0,3.25,7.0,5.25,2.0);
{ Bitmap 图片}
YPos := 3.4;
PrintCenter('PaintBitmapRect()',6.375);
Bitmap := TBitmap.Create;
Bitmap.LoadFromFile('RPDEMO.BMP');
PrintBitmapRect(5.375,3.5,7.375,5.5,Bitmap);
Bitmap.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
RvSystem1.Execute; //执行报表!
end;
end.
##################################################################################
本文地址:http://com.8s8s.com/it/it4418.htm