Solved

Create lines quick report delphi dbgrid

Posted on 2009-05-14
1
1,762 Views
Last Modified: 2013-11-22
I have some code to print a dbgrid from a dataset, what I need now is to create the lines between the data which will make the report to look like a grid also, I want to place a qrshape horline on each row and a vertline on each column.
procedure TTGridreport.Preview(grid: TDBGrid);

var

  i, CurrentLeft, CurrentTop : integer;

  BMark: TBookmark;

  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;
 

  GridRep.Bands.ColumnHeaderBand.Height:=Abs(Grid.TitleFont.Height) + 10;

  GridRep.Bands.DetailBand.Height:=Abs(Grid.Font.Height) + 10;

  CurrentLeft := 6;

  CurrentTop := 6;
 

  {Record where the user stopped in the DBGrid}

  BMark:=Grid.DataSource.DataSet.GetBookmark;

  {Don't let the grid flicker while the report is running}

  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;

      {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; 

        Caption:=Grid.Columns[i].Title.Caption;

      end; 

      {Create Detail with QRDBText}

      with TQRDbText.Create(GridRep.Bands.DetailBand) do 

      begin

        Parent := GridRep.Bands.DetailBand; 

        Color := GridRep.Bands.DetailBand.Color;

        Left := CurrentLeft; 

        Top := CurrentTop;

        Alignment:=Grid.Columns[i].Alignment; 

        AutoSize:=false;

        AutoStretch:=true; 

        Width:=Grid.Columns[i].Width;

        Dataset:=GridRep.Dataset;

        DataField:=Grid.Fields[i].FieldName;

        CurrentLeft:=CurrentLeft + (Grid.Columns[i].Width) + 10; 

      end;

    end; 
 

    lblPage.Left := bdTitle.Width - lblPage.Width - 10;

    lblDate.Left := bdTitle.Width - lblDate.Width - 10;
 

    {After all, call the QuickRep preview method}

    GridRep.PreviewModal; {or Preview if you prefer} 
 

  finally 

    with Grid.DataSource.DataSet do

    begin 

      GotoBookmark(BMark);

      FreeBookmark(BMark); 

      EnableControls;

    end; 

  end;

end;

Open in new window

0
Comment
Question by:kyriakos70
1 Comment
 
LVL 6

Accepted Solution

by:
bokist earned 500 total points
ID: 24392649
For this kind of report, I'm using TQRShape type qrsVertLine,
and for the bands (header, detail, footer..) > Frame.
You can achieve the goal, this way:

GridRep.Bands.ColumnHeaderBand.Frame.DrawTop := True;
GridRep.Bands.ColumnHeaderBand.Frame.DrawLeft := True;
GridRep.Bands.ColumnHeaderBand.Frame.DrawRigth := True;
GridRep.Bands.ColumnHeaderBand.Frame.DrawBottom := True;
GridRep.Bands.ColumnHeaderBand.Frame.Style := psSolid;
GridRep.Bands.ColumnHeaderBand.Frame.Width := 1;

GridRep.Bands.DetaiBand.Frame.DrawLeft := True;
GridRep.Bands.DetaiBand.Frame.DrawRigth := True;
GridRep.Bands.DetaiBand.Frame.DrawBottom := True;
GridRep.Bands.DetaiBand.Frame.Style := psSolid;

Regards,
    Steve
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
build html 5 client that connect to indy Tidtcpserver 3 350
Delphi cmd execution 6 55
Delphi Form ownership 4 70
URL for downloading Google Chrome for Win XP 2 118
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now