unit DBQRGridReport;
// DELPHI 7E.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,Controls, Forms,Dialogs, ExtCtrls, QuickRpt, QRCtrls,
DB, DBQRUnit1,
DBGrids,DBQRDataModul;
type
TGridReport =
class(TForm)
GridRep: TQuickRep;
procedure GridRepPreview(Grid : TDBGrid);
(* procedure GridRepBeforePrint(Sender: TCustomQuickRep;
var PrintReport: Boolean); *)
private
{ Private declarations }
public
end;
var
GridReport: TGridReport;
implementation
{$R *.dfm}
procedure TGridReport.GridRepPreview(Grid : TDBGrid);
var
i, CurrentLeft, CurrentTop : integer;
begin
GridRep.Dataset:=Grid.DataSource.DataSet;
if not GridRep.Bands.HasColumnHeader
then
GridRep.Bands.HasColumnHeader:=true;
if not GridRep.Bands.HasDetail
then
GridRep.Bands.HasDetail:=true;
if not GridRep.Bands.HasPageFooter
then // NEU
GridRep.Bands.HasPageFooter := TRUE;
GridRep.Bands.ColumnHeaderBand.Height:= Abs(Grid.TitleFont.Height) + 10;
GridRep.Bands.DetailBand.Height := Abs(Grid.Font.Height) + 10;
GridRep.Bands.PageFooterBand.Height := Abs(Grid.Font.Height) + 10;
CurrentLeft := 12;
CurrentTop := 4;
// 6
Grid.DataSource.DataSet.DisableControls;
// don't flicker !!
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;
{Create Header with QRLabels}
with TQRLabel.Create(GridRep.Bands.ColumnHeaderBand)
do
begin
Parent := GridRep.Bands.ColumnHeaderBand;
Color := GridRep.Bands.ColumnHeaderBand.Color;
Left := CurrentLeft;
Top := CurrentTop - 10;
// korr. !
Caption := Grid.Columns[i].Title.Caption;
Font.Style := [fsBold,fsUnderline];
end;
{Create Detail with QRDBText}
with TQRDBText.Create(GridRep.Bands.DetailBand)
do
begin
Parent := GridRep.Bands.DetailBand;
Color := GridRep.Bands.DetailBand.Color;
Transparent := TRUE;
// NEU für Farbwechsel
Left := CurrentLeft;
Top := CurrentTop;
Alignment := taLeftJustify;
// NEU / Alt -> Grid.Columns[i].Alignment;
AutoSize := FALSE;
AutoStretch := FALSE;
// korr. !
WordWrap := FALSE;
// NEU
Width := Grid.Columns[i].Width;
Dataset := GridRep.Dataset;
DataField := Grid.Fields[i].FieldName;
CurrentLeft := CurrentLeft + (Grid.Columns[i].Width) + 15;
end;
end;
{Create SysData / Datum-Zeit}
with TQRSysData.Create(GridRep.Bands.PageFooterBand)
do
begin
Parent := GridRep.Bands.PageFooterBand;
Color := clWhite;
Left := 12;
Top := CurrentTop;
Alignment := taLeftJustify;
Data := qrsDateTime;
Font.Charset := DEFAULT_CHARSET;
Font.Color := clWindowText;
Font.Height := -13;
Font.
Name := '
Arial';
Font.Style := [fsBold];
end;
{Create Label / TableName}
with TQRLabel.Create(GridRep.Bands.PageFooterBand)
do
begin
Parent := GridRep.Bands.PageFooterBand;
Color := clWhite;
Left := 512;
Top := CurrentTop;
Alignment := taLeftJustify;
Caption := '
TABLE 1';
Font.Charset := DEFAULT_CHARSET;
Font.Color := clWindowText;
Font.Height := -13;
Font.
Name := '
Arial';
Font.Style := [fsBold,fsUnderline];
end;
{Create Label / Seite :}
with TQRLabel.Create(GridRep.Bands.PageFooterBand)
do
begin
Parent := GridRep.Bands.PageFooterBand;
Color := clWhite;
Left := 948;
Top := CurrentTop;
Alignment := taLeftJustify;
Caption := '
SEITE :';
Font.Charset := DEFAULT_CHARSET;
Font.Color := clWindowText;
Font.Height := -13;
Font.
Name := '
Arial';
Font.Style := [fsBold];
end;
{Create SysData / Seitennummer}
with TQRSysData.Create(GridRep.Bands.PageFooterBand)
do
begin
Parent := GridRep.Bands.PageFooterBand;
Color := clWhite;
Left := 1024;
Top := CurrentTop;
Alignment := taLeftJustify;
Data := qrsPageNumber;
Font.Charset := DEFAULT_CHARSET;
Font.Color := clWindowText;
Font.Height := -13;
Font.
Name := '
Arial';
Font.Style := [fsBold];
end;
{After all, call the QuickRep preview method}
GridRep.Preview;
{or PreviewModal if you prefer}
finally
// FREE it NEU!
GridRep.Bands.ColumnHeaderBand.Free;
// wichtig sonst eListError
GridRep.Bands.DetailBand.Free;
// wichtig sonst eListError
GridRep.Bands.PageHeaderBand.Free;
// wichtig sonst eListError
with Grid.DataSource.DataSet
do
begin
EnableControls;
end;
end;
end;
// Für Tabellierpapier
(* procedure TGridReport.GridRepBeforePrint(Sender: TCustomQuickRep;
var PrintReport: Boolean);
begin
If GridReport.DetailBandXXX.Color = clWhite THEN
GridReport.DetailBandXXX.Color := clMoneyGreen ELSE
GridReport.DetailBandXXX.Color := clWhite;
end; *)
end.