Solved

Problems printing a simple textfile from Delphi

Posted on 1997-07-22
5
203 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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