Solved

Problems printing a simple textfile from Delphi

Posted on 1997-07-22
5
217 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

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…

830 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