Solved

PrinterIndex not working with TPrintDialog

Posted on 1998-03-03
1
481 Views
Last Modified: 2008-02-01
If I change the printer using the PrinterIndex property of Printer,
and then call PrintDialog.Execute (assuming PrintDialog is of type
TPrintDialog) it will show the settings for the default printer.

If I change the printer selected via the print dialog and then click
OK, and change the printer again via PrinterIndex, and finally show
the print dialog again, it shows the previously selected printed as
when the dialog was last open.

what gives? how can I make this work without having to resort to using
the Window API?

thanks in advance,
David
0
Comment
Question by:dl090597
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 8

Accepted Solution

by:
ZifNab earned 50 total points
ID: 1360066
Hi dl,

maybe this answers your question :

Changing the port of a printer

                          Question:

                          How can I change the port a given printer will use in code?

                          Answer:

                          You can use the SetPrinter method of TPrinter to change the port.
                          The following example demonstrates changing the port to print to a
                          file.

                          Example:

                          uses Printers;

                          {$IFNDEF WIN32}
                           const MAX_PATH = 144;
                          {$ENDIF}

                          procedure TForm1.Button1Click(Sender: TObject);
                          var
                            pDevice : pChar;
                            pDriver : pChar;
                            pPort   : pChar;
                            hDMode : THandle;
                            PDMode : PDEVMODE;
                          begin
                            if PrintDialog1.Execute then begin
                              GetMem(pDevice, cchDeviceName);
                              GetMem(pDriver, MAX_PATH);
                              GetMem(pPort, MAX_PATH);
                              Printer.GetPrinter(pDevice, pDriver, pPort, hDMode);
                              Printer.SetPrinter(pDevice, PDriver, 'FILE:', hDMode);
                              FreeMem(pDevice, cchDeviceName);
                              FreeMem(pDriver, MAX_PATH);
                              FreeMem(pPort, MAX_PATH);
                              Printer.BeginDoc;
                              Printer.Canvas.TextOut(100, 100, 'Delphi Is RAD!');
                              Printer.EndDoc;
                            end;
                          end;
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question