Solved

PrinterIndex not working with TPrintDialog

Posted on 1998-03-03
1
479 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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