var
GridReport: TGridReport;
implementation
{$R *.dfm}
procedure
TGridReport
.
Preview(Grid:TDBGrid);
var
i, CurrentLeft, CurrentTop :
integer
;
BMark:TBookmark;
begin
GridRep
.
Dataset:=Grid
.
DataSource
.
DataSet;
GridRep
.
Bands
.
HasTitle:=
true
;
GridRep
.
Bands
.
TitleBand
.
Height:=
150
;
with
TQRLabel
.
Create(GridRep
.
Bands
.
TitleBand)
do
begin
Parent := GridRep
.
Bands
.
TitleBand;
Left :=
7
;
Top :=
7
;
Color:=
$00ADADAD
;
Font
.
Size:=
55
;
Caption:=
'Заголовок отчета. '
;
end
;
GridRep
.
Bands
.
HasPageHeader:=
true
;
GridRep
.
Bands
.
PageHeaderBand
.
Height:=
100
;
with
TQRLabel
.
Create(GridRep
.
Bands
.
PageHeaderBand)
do
begin
Parent := GridRep
.
Bands
.
PageHeaderBand;
Left :=
7
;
Top :=
7
;
Font
.
Size:=
16
;
Caption:=
'Этот текст будет отображаться вначале каждой страницы...'
;
end
;
GridRep
.
Bands
.
HasPageFooter:=
true
;
GridRep
.
Bands
.
PageFooterBand
.
Height:=
100
;
with
TQRLabel
.
Create(GridRep
.
Bands
.
PageFooterBand)
do
begin
Parent := GridRep
.
Bands
.
PageFooterBand;
Left :=
7
;
Top :=
7
;
Font
.
Size:=
16
;
Caption:=
'Этот текст будет отображаться в конце каждой страницы...'
;
end
;
GridRep
.
Bands
.
HasSummary:=
true
;
GridRep
.
Bands
.
SummaryBand
.
Height:=
500
;
with
TQRLabel
.
Create(GridRep
.
Bands
.
SummaryBand)
do
begin
Parent := GridRep
.
Bands
.
SummaryBand;
Left :=
7
;
Top :=
15
;
Font
.
Size:=
16
;
Caption:=
'Этот текст будет отображаться в конце всего отчета..'
;
end
;
if
not
GridRep
.
Bands
.
HasColumnHeader
then
GridRep
.
Bands
.
HasColumnHeader:=
true
;
if
not
GridRep
.
Bands
.
HasDetail
then
GridRep
.
Bands
.
HasDetail:=
true
;
GridRep
.
Bands
.
ColumnHeaderBand
.
Height:=
Abs
(Grid
.
TitleFont
.
Height) +
10
;
GridRep
.
Bands
.
DetailBand
.
Height:=
Abs
(Grid
.
Font
.
Height) +
10
;
CurrentLeft :=
12
;
CurrentTop :=
6
;
BMark:=Grid
.
DataSource
.
DataSet
.
GetBookmark;
Grid
.
DataSource
.
DataSet
.
DisableControls;
try
for
i:=
0
to
Grid
.
FieldCount -
1
do
begin
if
(CurrentLeft + Canvas
.
TextWidth(Grid
.
Columns[i].Title
.
Caption)) >
(GridRep
.
Bands
.
ColumnHeaderBand
.
Width)
then
begin
CurrentLeft :=
12
;
CurrentTop := CurrentTop + Canvas
.
TextHeight(
'A'
) +
6
;
GridRep
.
Bands
.
ColumnHeaderBand
.
Height :=
GridRep
.
Bands
.
ColumnHeaderBand
.
Height + (Canvas
.
TextHeight(
'A'
) +
10
);
GridRep
.
Bands
.
DetailBand
.
Height :=
GridRep
.
Bands
.
DetailBand
.
Height + (Canvas
.
TextHeight(
'A'
) +
10
);
end
;
GridRep
.
Bands
.
ColumnHeaderBand
.
Color:=
$00959595
;
with
TQRLabel
.
Create(GridRep
.
Bands
.
ColumnHeaderBand)
do
begin
Parent := GridRep
.
Bands
.
ColumnHeaderBand;
Color := GridRep
.
Bands
.
ColumnHeaderBand
.
Color;
Left := CurrentLeft+
25
;
Top := CurrentTop;
Caption:=Grid
.
Columns[i].Title
.
Caption;
Alignment:=taCenter;
end
;
with
TQRDbText
.
Create(GridRep
.
Bands
.
DetailBand)
do
begin
Parent := GridRep
.
Bands
.
DetailBand;
Color := GridRep
.
Bands
.
DetailBand
.
Color;
Left := CurrentLeft;
Top := CurrentTop;
Alignment:=taCenter;
AutoSize:=
false
;
AutoStretch:=
true
;
Width:=Grid
.
Columns[i].Width;
Dataset:=GridRep
.
Dataset;
DataField:=Grid
.
Fields[i].FieldName;
CurrentLeft:=CurrentLeft + (Grid
.
Columns[i].Width +
15
);
end
;
end
;
GridRep
.
PreviewModal;
finally
with
Grid
.
DataSource
.
DataSet
do
begin
GotoBookmark(BMark);
FreeBookmark(BMark);
EnableControls;
end
;
end
;
end
;