Solved

PrinterIndex not working with TPrintDialog

Posted on 1998-03-03
1
471 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
1 Comment
 
LVL 8

Accepted Solution

by:
ZifNab earned 50 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now