AssignPrn
Belongs to : ProcedureDescription
The AssignPrn procedure assigns the printer to a FileHandle. This means that subsequent text writing to this file gets rerouted to the printer. This provides a simpl and easy way of dumping out text to a printer.
Notes
Warning : The AssignPrn mechanism is useful for simple programs, but lacks any control over printing for a real application.
Example code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
var myFile : TextFile; printDialog : TPrintDialog; begin // Create a printer selection dialog printDialog := TPrintDialog.Create(Form1); // If the user has selected a printer (or default), then print! if printDialog.Execute then begin // Try to open a printer file AssignPrn(myFile); // Now prepare to write to the printer ReWrite(myFile); // Write a couple of well known words to this file - // they will be printed instead WriteLn(myFile, 'Hello'); WriteLn(myFile, 'World'); // Close the file CloseFile(myFile); end; end; { After the user selects a printer, the following text is printed in a small font at the top left of the page: Hello World } |