AssignPrn Printing


One of the easiest ways to output text to the printer is to use the AssignPrn procedure, which enables you to assign a text file to the printer and use the WriteLn procedure to print text on the printer. When you assign a text file to the printer, you must call the Rewrite procedure to begin printing. When you're done printing, close the printer by calling CloseFile. Finally, to use the AssignPrn procedure and other printing related types, classes, and routines, you have to add the Printers unit to the uses list.

Here's an example of how you can use the AssignPrn procedure to output text to the printer:

procedure TMainForm.AssignPrintingClick(Sender: TObject); var   F: TextFile; begin   AssignPrn(F); { you need the Printers unit for this }   try     Rewrite(F); { must Rewrite when using AssignPrn }     WriteLn(F, 'Hello from Delphi.');   finally     CloseFile(F);   end; end;

Figure 27-1 shows the output of the above code.

image from book
Figure 27-1: The result of AssignPrn printing



Inside Delphi 2006
Inside Delphi 2006 (Wordware Delphi Developers Library)
ISBN: 1598220039
EAN: 2147483647
Year: 2004
Pages: 212
Authors: Ivan Hladni

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net