Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sample of printing draw/string Grid Contents

Posted on 1998-06-19
1
Medium Priority
?
1,182 Views
Last Modified: 2008-02-01
I'm looking for a good sample of how to print the contents of a string or draw grid.
0
Comment
Question by:blitz051697
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
vladika earned 400 total points
ID: 1354394
The main idea: use QuickReport and OnNeedData event

Here is example

// ----------------
unit Main;

interface

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

type
  TTest = class(TForm)
    StringGrid: TStringGrid;
    TestFillBtn: TButton;
    TestPrintBtn: TButton;
    procedure TestFillBtnClick(Sender: TObject);
    procedure TestPrintBtnClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Test: TTest;

implementation

uses PrnFrm;

{$R *.DFM}

procedure TTest.TestFillBtnClick(Sender: TObject);
var I, J: Integer;
begin
  for I := 0 to StringGrid.RowCount-1 do
    for J := 0 to StringGrid.ColCount-1 do
      StringGrid.Cells[J,I] := Format('Test %d %d', [I, J]); // fill StringGrid with test value
end;

procedure TTest.TestPrintBtnClick(Sender: TObject);
begin
  PrintForm.StringGrid := StringGrid;
  PrintForm.QuickRep.Preview;  // preview report
end;

end.
// ------- end of Main Unit -----

object Test: TTest
  Left = 206
  Top = 139
  Width = 367
  Height = 330
  Caption = 'Test'
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  PixelsPerInch = 96
  TextHeight = 13
  object StringGrid: TStringGrid
    Left = 8
    Top = 8
    Width = 225
    Height = 281
    ColCount = 3
    FixedCols = 0
    RowCount = 100
    FixedRows = 0
    TabOrder = 0
  end
  object TestFillBtn: TButton
    Left = 256
    Top = 8
    Width = 75
    Height = 25
    Caption = 'Test Fill'
    TabOrder = 1
    OnClick = TestFillBtnClick
  end
  object TestPrintBtn: TButton
    Left = 256
    Top = 56
    Width = 75
    Height = 25
    Caption = 'Test Print'
    TabOrder = 2
    OnClick = TestPrintBtnClick
  end
end

// ---- end of Test Form (Main program form)

unit PrnFrm;

interface

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

type
  TPrintForm = class(TForm)
    QuickRep: TQuickRep;
    QRBand1: TQRBand;
    QRLabel1: TQRLabel;
    QRLabel2: TQRLabel;
    QRLabel3: TQRLabel;
    procedure QuickRepNeedData(Sender: TObject; var MoreData: Boolean);
    procedure QuickRepBeforePrint(Sender: TQuickRep;
      var PrintReport: Boolean);
  private
    { Private declarations }
    FStringGrid: TStringGrid;
    FCurrentRow: Integer;
  public
    { Public declarations }
    property StringGrid: TStringGrid read FStringGrid write FStringGrid;
  end;

var
  PrintForm: TPrintForm;

implementation

{$R *.DFM}

procedure TPrintForm.QuickRepNeedData(Sender: TObject; var MoreData: Boolean);
begin
  MoreData := FCurrentRow < FStringGrid.RowCount;
  if not MoreData then Exit;  // no more data

  QRLabel1.Caption := FStringGrid.Cells[0, FCurrentRow];  // set report data from StringGrid
  QRLabel2.Caption := FStringGrid.Cells[1, FCurrentRow];
  QRLabel3.Caption := FStringGrid.Cells[2, FCurrentRow];
  Inc(FCurrentRow);
end;

procedure TPrintForm.QuickRepBeforePrint(Sender: TQuickRep;
  var PrintReport: Boolean);
begin
  FCurrentRow := 0;  // init CurrentRow
end;

end.
// ------ end of PrnFrm Unit

object PrintForm: TPrintForm
  Left = 200
  Top = 108
  Width = 544
  Height = 375
  Caption = 'PrintForm'
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  Scaled = False
  PixelsPerInch = 96
  TextHeight = 13
  object QuickRep: TQuickRep
    Left = 0
    Top = 0
    Width = 794
    Height = 1123
    Frame.Color = clBlack
    Frame.DrawTop = False
    Frame.DrawBottom = False
    Frame.DrawLeft = False
    Frame.DrawRight = False
    BeforePrint = QuickRepBeforePrint
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -13
    Font.Name = 'Arial'
    Font.Style = []
    OnNeedData = QuickRepNeedData
    Options = [FirstPageHeader, LastPageFooter]
    Page.Columns = 1
    Page.Orientation = poPortrait
    Page.PaperSize = A4
    Page.Values = (
      100
      2970
      100
      2100
      100
      100
      0)
    PrintIfEmpty = False
    PrinterSettings.Copies = 1
    PrinterSettings.Duplex = False
    PrinterSettings.FirstPage = 0
    PrinterSettings.LastPage = 0
    PrinterSettings.OutputBin = First
    SnapToGrid = True
    Units = MM
    Zoom = 100
    object QRBand1: TQRBand
      Left = 38
      Top = 38
      Width = 718
      Height = 35
      Frame.Color = clBlack
      Frame.DrawTop = False
      Frame.DrawBottom = False
      Frame.DrawLeft = False
      Frame.DrawRight = False
      AlignToBottom = False
      Color = clWhite
      ForceNewColumn = False
      ForceNewPage = False
      Size.Values = (
        92.6041666666667
        1899.70833333333)
      BandType = rbDetail
      object QRLabel1: TQRLabel
        Left = 24
        Top = 0
        Width = 58
        Height = 17
        Frame.Color = clBlack
        Frame.DrawTop = False
        Frame.DrawBottom = False
        Frame.DrawLeft = False
        Frame.DrawRight = False
        Size.Values = (
          44.9791666666667
          63.5
          0
          153.458333333333)
        Alignment = taLeftJustify
        AlignToBand = False
        AutoSize = True
        AutoStretch = False
        Caption = 'QRLabel1'
        Color = clWhite
        Transparent = False
        WordWrap = True
        FontSize = 10
      end
      object QRLabel2: TQRLabel
        Left = 248
        Top = 0
        Width = 58
        Height = 17
        Frame.Color = clBlack
        Frame.DrawTop = False
        Frame.DrawBottom = False
        Frame.DrawLeft = False
        Frame.DrawRight = False
        Size.Values = (
          44.9791666666667
          656.166666666667
          0
          153.458333333333)
        Alignment = taLeftJustify
        AlignToBand = False
        AutoSize = True
        AutoStretch = False
        Caption = 'QRLabel2'
        Color = clWhite
        Transparent = False
        WordWrap = True
        FontSize = 10
      end
      object QRLabel3: TQRLabel
        Left = 472
        Top = 0
        Width = 58
        Height = 17
        Frame.Color = clBlack
        Frame.DrawTop = False
        Frame.DrawBottom = False
        Frame.DrawLeft = False
        Frame.DrawRight = False
        Size.Values = (
          44.9791666666667
          1248.83333333333
          0
          153.458333333333)
        Alignment = taLeftJustify
        AlignToBand = False
        AutoSize = True
        AutoStretch = False
        Caption = 'QRLabel3'
        Color = clWhite
        Transparent = False
        WordWrap = True
        FontSize = 10
      end
    end
  end
end

// end of Print Form

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

610 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