AssignPrnBelongs to : Procedure
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.
Warning : The AssignPrn mechanism is useful for simple programs, but lacks any control over printing for a real application.
myFile : TextFile;
printDialog : TPrintDialog;
// Create a printer selection dialog
printDialog := TPrintDialog.Create(Form1);
// If the user has selected a printer (or default), then print!
if printDialog.Execute then
// Try to open a printer file
// Now prepare to write to the printer
// Write a couple of well known words to this file -
// they will be printed instead
// Close the file
After the user selects a printer, the following text is printed in a small font at the top left of the page: