Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 03-18-2006, 10:49 PM
Jasser Jasser is online now
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,060
Default Printing using none default printer.

How to print a report using the none default printer? I use Delphi 7 + Quick Report.

Regards,
Abdulaziz Jasser
Reply With Quote
  #2  
Old 03-18-2006, 11:28 PM
Ryan Ryan is offline
Senior Member
 
Join Date: Feb 2001
Posts: 417
Default RE: Printing using none default printer.

You should have a "PrintDialog" control under the Dialogs Tab, drop it on the form.

Assuming you call it PD1, you can call it like this:

[delphi]
procedure TForm1.DoPrinting;
begin
if PD1.execute then begin
PrintMyReport;
// Here the User have selected the correct printer in
// the dialog and it will automatically communicate
// that to Delphi's TPrinter object, no need for you
// to do anything else. (You must have "Printers" in your
// Uses clause).
end;
end;

// If you want to decide it in code, and not by the user,
// you have to still put "Printers" in your uses clause,
// then call:
Printer.EnumeratePrinters(MyList);
// (I think, it should be obvious), where "MyList" is a
// TStringList you created and after that call contains
// the names of all connected printers. You then use:
Printer.SetPrinter(MyPrinterSelection);
// (Again, I think, it should be obvious) where
// MyPrinterSelection is a string representing one of
// the names from MyList. This is helpful if you want to
// save the selection so the next time the user prints,
// you make it go to the last selected printer etc....
[/delphi]

Cheers!


"I don't care about the points, I only care about Programming..."

Ryan
Reply With Quote
  #3  
Old 03-19-2006, 08:51 AM
Jasser Jasser is online now
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,060
Default RE: Printing using none default printer.

Would this code affect the default printer on the other reports? In other words, I am going to use the code for one report in my application. What it is going to happen to the other reports in my application those who use the default printer?

Regards,
Abdulaziz Jasser
Reply With Quote
  #4  
Old 03-19-2006, 11:50 AM
Ryan Ryan is offline
Senior Member
 
Join Date: Feb 2001
Posts: 417
Default RE: Printing using none default printer.

Well, there is only one default printer, but this is not set in your prog, this is done only in Windows.

As for your code, once the Printer is changed, it stays changed for the session, but if the program is closed, and started again, it's back to the default printer.

If this is a big concern for you, I suggest you keep record of which reports use which printers. You can make your own Printer selection form where you could put the printers in a dialog box and have the user select one. Then remember which reports used which printer.

A less demanding idea would be to simply store the name of the default printer on program startup as well as load the name of the printer to use for the special case, then in your code simply set the correct printer for the special case and the default for all others. I must mention that my experience with users are that they would like to be kept in the loop on deciding which printer to print to, plus they would like have the thing remember so they don't have to choose the next time round.

Cheers!


"I don't care about the points, I only care about Programming..."

Ryan
Reply With Quote
  #5  
Old 03-19-2006, 01:28 PM
Jasser Jasser is online now
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,060
Default RE: Printing using none default printer.

There are no special cases, itís only one report out of one program looking to be sent only for a none default Windows printer. How can achieve that?

Regards,
Abdulaziz Jasser
Reply With Quote
  #6  
Old 03-19-2006, 01:49 PM
Ryan Ryan is offline
Senior Member
 
Join Date: Feb 2001
Posts: 417
Default RE: Printing using none default printer.

Well then, if it's that boring...

Let's imagine your printer's name is 'LexmarkZebraDX11', then A simple:

[delphi]
uses Printers;

procedure PrintToSpecialPrinter;
var i:integer;
begin
i:=Printer.Printers.IndexOf('LexmarkZebraDX11');
Printer.PrinterIndex:=i; // Sets the new Printer
PrintMyReport; // Print your report
Printer.PrinterIndex:=-1; // Resets to default printer
end;
[/delphi]
Note: if the name 'LexmarkZebraDX11' cannot be found, the default printer will still be used.

Cheers!


"I don't care about the points, I only care about Programming..."

Ryan
Reply With Quote
  #7  
Old 03-19-2006, 03:52 PM
BaraoZemo BaraoZemo is offline
Senior Member
 
Join Date: Nov 2001
Posts: 3,598
Default RE: Printing using none default printer.

hi jasser,

you could use this one..

http://bak-o-soft.dk/Default.asp?Page=PBPrinterSetupDialog

Regards
BaraoZemo

ps, don't forget to click in the button and Accept as Answer if this helped you!
Reply With Quote
  #8  
Old 03-19-2006, 04:50 PM
BaraoZemo BaraoZemo is offline
Senior Member
 
Join Date: Nov 2001
Posts: 3,598
Default RE: Printing using none default printer.

i wrote my own sample..

download "printersetup"

http://ciberia.ya.com/mcgvix/stuff.htm

Regards
BaraoZemo

ps, don't forget to click in the button and Accept as Answer if this helped you!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 05:41 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.