Solved

Print job

Posted on 2003-11-18
9
296 Views
Last Modified: 2010-04-06
I have a from with a StringGrid and some data in it
I want to print this from on a printer
i use PrintDialog
i use PrintDialog1.Execute
on the dialog box i select the right printer but when i click OK nothing happend
i read over the internet some examples
i see PrinDialog.BeginDoc but give me error undeclared identifier BeginDoc
i use also the Delphi unit Printers
But nothing happend also
Tell me how can i print my form
Thanks
0
Comment
Question by:fradolcino
[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
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 8

Expert Comment

by:gmayo
ID: 9770490
The PrintDialog doesn't do the printing, it simply allows you to select the printer. Use the unit Printers. In your code use Printer.BeginDoc etc.

Geoff M.
0
 

Author Comment

by:fradolcino
ID: 9770534
Perhaps gmayo don't read all my comments
I specify a use Printers unit but the same error
Thanks
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9770538
a sample from the delphi online help:

procedure TForm1.Button1Click(Sender: TObject);
var
  r: TRect;
  i: Integer;
begin
  with Printer do
    begin
      r := Rect(200,200,(Pagewidth - 200),(PageHeight - 200));
      BeginDoc;
      Canvas.Brush.Style := bsClear;
      for i := 0 to Memo1.Lines.Count do
       Canvas.TextOut(200,200 + (i *
                   Canvas.TextHeight(Memo1.Lines.Strings[i])),
                   Memo1.Lines.Strings[i]);

      Canvas.Brush.Color := clBlack;
      Canvas.FrameRect(r);
      EndDoc;
    end;
end;

meikl ;-)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:gmayo
ID: 9770792
I did. Perhaps you didn't read mine, in which I said:
"use Printer.BeginDoc".

Geoff M.
0
 

Author Comment

by:fradolcino
ID: 9770882
thanks meikl
but i have a StringGrid
Whould you advice me how to print the StringGrid
Thanks
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9770928
this is not so easy,
because u have to draw the grid
byself on the printer-canvas or
u could use the paintto-method for this

go to
www.torry.net
there are some stringgrids with printing support

meikl ;-)
0
 
LVL 2

Expert Comment

by:gangsterboss
ID: 9773243
to print a form just put

procedure button1click (Sender:TObject);
begin
form1.print;
end;

0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9773838
funny gangsterboss :-))

and if the content does not fit on the form?
0
 
LVL 2

Accepted Solution

by:
gangsterboss earned 55 total points
ID: 9775719
well i didn't realy think about that but u could make everything u need large enough to display all of the content eg

var i,j :integer;
begin
i:=stringgrid1.width;
j:=stringgrid1.height;
stringgrid1.width:= stringgrid1.colwidth*stringgrid1.colcount;
stringgrid1.height:= stringgrid1.rowwidth*stringgrid1.rowcount;
form1.width:= form1.width + (stringgrid1.width-i)
form1.height:= form1.height+ (stringgrid1.height-j)
form1.print
end;

but heres some could to just print the stringgrid with a title

uses
  Printers;

procedure PrintGrid(sGrid: TStringGrid; sTitle: string);
var
  X1, X2: Integer;
  Y1, Y2: Integer;
  TmpI: Integer;
  F: Integer;
  TR: TRect;
begin
  Printer.Title := sTitle;
  Printer.BeginDoc;
  Printer.Canvas.Pen.Color  := 0;
  Printer.Canvas.Font.Name  := 'Times New Roman';
  Printer.Canvas.Font.Size  := 12;
  Printer.Canvas.Font.Style := [fsBold, fsUnderline];
  Printer.Canvas.TextOut(0, 100, Printer.Title);
  for F := 1 to sGrid.ColCount - 1 do  
  begin
    X1 := 0;
    for TmpI := 1 to (F - 1) do
      X1 := X1 + 5 * (sGrid.ColWidths[TmpI]);
    Y1 := 300;
    X2 := 0;
    for TmpI := 1 to F do
      X2 := X2 + 5 * (sGrid.ColWidths[TmpI]);
    Y2 := 450;
    TR := Rect(X1, Y1, X2 - 30, Y2);
    Printer.Canvas.Font.Style := [fsBold];
    Printer.Canvas.Font.Size := 7;
    Printer.Canvas.TextRect(TR, X1 + 50, 350, sGrid.Cells[F, 0]);
    Printer.Canvas.Font.Style := [];
    for TmpI := 1 to sGrid.RowCount - 1 do  
    begin
      Y1 := 150 * TmpI + 300;
      Y2 := 150 * (TmpI + 1) + 300;
      TR := Rect(X1, Y1, X2 - 30, Y2);
      Printer.Canvas.TextRect(TR, X1 + 50, Y1 + 50, sGrid.Cells[F, TmpI]);
    end;
  end;
  Printer.EndDoc;
end;


//Examplem

procedure TForm1.Button1Click(Sender: TObject);
begin
  PrintGrid(StringGrid1, 'Title');
end;

is this ok now  kretzschmar it took me a while to write this and my 1st lang isn't english  and i only been doing delphi for about 2 months
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

728 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