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
Solved

Print job

Posted on 2003-11-18
9
294 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
  • 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

829 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