Solved

PrinterIndex not working with TPrintDialog

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

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…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

831 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