Solved

PrinterIndex not working with TPrintDialog

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi - replicating a form 8 81
Tviruailstringtree sort multi columns on header click 1 74
How to load 2 images in same column in Delphi 2 57
RESTRequest Parameter 4 43
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…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
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…

861 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