Solved

Print job

Posted on 2003-11-18
9
284 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

15 Experts available now in Live!

Get 1:1 Help Now