Solved

Print job

Posted on 2003-11-18
9
292 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 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