Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing the default printer for a Delphi application ? 2

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
Am I able to change the default printer for a delphi application that I am running.
That is, I have a default printer set up (call it PRINTER_ONE) for Windows.
When I run my Delphi application I want the default printer to change to PRINTER_TWO. Is this do-able for the duration of the program that I am running ?
I don't want to change the default printer for Windows as a whole - else this will cause problems if I have any other applications open that may need to be printed from (i.e. OutLook, Word, etc.)
I want the printer to be changed for the scope of the application / session running.
Is this achievable ?
I could be missing something very simple here.
Any help would be appreciated.
Steve
 
Not a default printer but why not simply assign the printer you desire in the printers object?
 
Try:
There is a global Tprinter object called Printer.
Printer.PrinterIndex := Printer.Printers.IndexOf('PrinterName');

If you wanted to be clever, you could put all of the printers in the Printer.Printers string list into a list box. and then do something like:

ListBox.Items := Printer.Printers;
if ListBox.ItemIndex > -1 then
Printer.PrinterIndex := ListBox.ItemIndex;

I've used this in the past so I know that it works. You have to have the correct name in the PrinterName parameter. I don't think you have to reassign the default printer back into the property but I may be wrong there.
 
Excellent + speedy responses.
It is a simple case of setting the printer index :
i.e. QuickReport1.PrinterSettings.PrinterIndex := 2;

Thanks again.
Steve
 
Steve,

You may be interested in a related article at which shows how to connect your QuickReports to the selected printer in the PRINTERS unit. If you're planning on providing a File | Printer Setup commend from your main menu, it may prove helpful.

(The underlying technique is very similar to what's already been described, however, I prefer to connect my reports to whatever's selected in the PRINTERS unit, rather than setting it to arbitrary index values at run time. This way, all report instances respond to the TPrinterSetup dialog, which in turn allows for more flexible applications, IMHO. YMMV.)

Hope this helps...

-- Lance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top