Solved

Problems printing a simple textfile from Delphi

Posted on 1997-07-22
5
212 Views
Last Modified: 2010-04-04
This is the first time I try to do this. Printing a textfile from a Delphi program. I'm not sure if I'm doing it the right way. I read the textfile line by line and copy the read line in a variable (string) then I call the method printer.canvas.textout(x,y,string) in which x and y are variables updated elsewhere in the program. The debugger shows that the string is filled with lines from the textfile,but the method don't seem to work properly,because all I get after sending the job with printer.enddoc is an empty page. The debugger shows that the canvas is not updated by the method.  I suppose I forgot something. Any body can help me out?
0
Comment
Question by:lizzzard
5 Comments
 
LVL 2

Expert Comment

by:icampbe1
ID: 1339464
Put a PrintDialog on your form and then:

USES Printers;

IF PrintDialog1.Execute THEN BEGIN
   WITH Printer DO BEGIN
      BeginDoc;
      ....
      canvas.TextOut( x, y, str );
      .....
      EndDoc;
      END;  {Of with printer}
   END;

This should work for you.
Cheers,
Ian C.

0
 

Author Comment

by:lizzzard
ID: 1339465
What Icambe suggested is already the way I coded it. That's why I can't figure out why my printer doesn't print anything. (And eh.. it's not that I'm out of ink.)
0
 

Expert Comment

by:M_Hoeper
ID: 1339466
Please send your whole print code.
0
 
LVL 6

Accepted Solution

by:
rcastle earned 50 total points
ID: 1339467
What IanC suggested should work.  Please send your code to
rcastle@reell.com

Here is my spin on it

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    PrintDialog1: TPrintDialog;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
IF PrintDialog1.Execute THEN
BEGIN
 WITH Printer DO
 BEGIN
  BeginDoc;
  canvas.TextOut( 1, 1, 'hello' );
  EndDoc;
 END; {Of with printer}
END;
end;

end.

Thanx
0
 

Author Comment

by:lizzzard
ID: 1339468
Ok,problem solved. Thx
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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 Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

777 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