Einzelnen Beitrag anzeigen

grayfox

Registriert seit: 22. Jan 2003
Ort: Litschau
173 Beiträge
 
Delphi 4 Standard
 
#9

Re: StringGrid im QuickReport

  Alt 12. Jan 2004, 01:40
hallo moin!

versuch es mal so....

Code:
unit Mainprog;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Buttons, StdCtrls, Grids;

type
  TForm1 = class(TForm)
    EndeBtn: TButton;
    BitBtn1: TBitBtn;
    Grid1: TStringGrid;
    procedure EndeBtnClick(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

uses PrintDlgFrm;

{$R *.DFM}

procedure TForm1.EndeBtnClick(Sender: TObject);
begin
  close;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  aWindowState: TWindowState;
begin
  aWindowState:= WindowState;
  try
    PrintFrm:= TPrintFrm.Create(self);
    PrintFrm.Init(Grid1);
    PrintFrm.QuickRep1.Preview;
  finally
    if PrintFrm <> nil then
      PrintFrm.Free;
    WindowState:= aWindowState;
  end;
end;

procedure TForm1.FormShow(Sender: TObject);
var
  aRow: ShortInt;
begin
  with Grid1 do begin
    Colwidths[0]:= 20;
    Colwidths[1]:= 80;
    Colwidths[2]:= 80;
    Colwidths[3]:= 80;
    Colwidths[4]:= 80;
    Cells[0,0]:= 'lfdNr';
    Cells[1,0]:= 'Art_Sorte';
    Cells[2,0]:= 'Art_Gruppe';
    Cells[3,0]:= 'Inhalt';
    Cells[4,0]:= 'Preis';
    for aRow:= 1 to RowCount-1 do begin
      Cells[0,aRow]:= IntToStr(aRow);
      Cells[1,aRow]:= 'Artikel ' + IntToStr(10000 + aRow);
      if (aRow mod 2) = 0 then
        Cells[2,aRow]:= 'Wein'
      else
        Cells[2,aRow]:= 'Sekt';
      Cells[3,aRow]:= '0,75 l';
      Cells[4,aRow]:= FloatToStr(4.20 + aRow);
    end;
  end;
end;

end.


------------------------------------------------------------------------------------------------

unit PrintDlgFrm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, QuickRpt, Qrctrls, Grids;

type
  TPrintFrm = class(TForm)
    QuickRep1: TQuickRep;
    PageFooterBand1: TQRBand;
    DetailBand1: TQRBand;
    PageHeaderBand1: TQRBand;
    QRLabel1: TQRLabel;
    QRLabel2: TQRLabel;
    QRLabel3: TQRLabel;
    QRLabel4: TQRLabel;
    QRSysData1: TQRSysData;
    QRLabel5: TQRLabel;
    ColumnHeaderBand1: TQRBand;
    QRLabel6: TQRLabel;
    QRLabel7: TQRLabel;
    QRLabel8: TQRLabel;
    QRLabel9: TQRLabel;
    QRLabel10: TQRLabel;
    procedure QuickRep1BeforePrint(Sender: TCustomQuickRep;
      var PrintReport: Boolean);
    procedure QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private-Deklarationen }
     ZeileNr: integer;
     maxZeilen: integer;
     maxSeiten: integer;
     aGrid: TStringGrid;
  public
    { Public-Deklarationen }
    procedure Init(DGrid: TStringGrid);
  end;

var
  PrintFrm: TPrintFrm;

implementation

{$R *.DFM}

procedure TPrintFrm.Init(DGrid: TStringGrid);
begin
  aGrid:= TStringGrid.Create(self);
  aGrid:= dGrid;
  maxZeilen:= aGrid.RowCount;
  QuickRep1.Prepare;
  maxSeiten:= QuickRep1.PageNumber;
  qrLabel10.Caption:= ' von ' + IntToStr(maxSeiten) + ' Seiten'
end;


procedure TPrintFrm.QuickRep1BeforePrint(Sender: TCustomQuickRep;
  var PrintReport: Boolean);
begin
  ZeileNr:= 0;
end;


procedure TPrintFrm.QuickRep1NeedData(Sender: TObject;
  var MoreData: Boolean);
begin
  MoreData:= (ZeileNr < maxZeilen);
  if MoreData then begin
    QRLabel2.Caption:= aGrid.Cells[0,ZeileNr+1];
    QRLabel3.Caption:= aGrid.Cells[1,ZeileNr+1];
    QRLabel4.Caption:= aGrid.Cells[2,ZeileNr+1];
    QRLabel5.Caption:= aGrid.Cells[3,ZeileNr+1]
  end;
  inc(ZeileNr)
end;

procedure TPrintFrm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if aGrid <> nil then
    aGrid.Free;
end;

end.
damit sollte dein stringgrid problemlos ausgedruckt werden

mfg, stefan
  Mit Zitat antworten Zitat