Re:TPrinter.PrinterIndex
Quote
Rocio Snchez <aro...@colomsat.net.co> wrote in message
news:37BCE4C1.9C944BEF@colomsat.net.co...
Quote
> Hi,
> I am having a curious problem with this property. A client has an
> application that works with the class TPrinter to change the default
> printer, I mean, the printer that must be shown in the moment the
> TPrintDialog executes. But nothing change, and I tried it in my
> computer and everything works OK, and exactly the same application.
> All my application does is:
> Var
> Printer : TPrinter ;
> Printer.PrinterIndex := 0 ;
> PrintDialog1.execute ;
> That's it. But it doesn't work in the other computer.
> Thank you,
> Rocio
=====================================================
I also faced almost similer problem and I solve it using the following
replay from TeamB.
Quote
> I want to use two printers are used in an application. One is the default
> Printer with paper size 8.5 x 12 inches(Printer Index 1) and other one is
a
> paper setting of 8.5 x 4 inches(Printer Index 0).
> While changing from first one to second one from with in the application
the
> paper size is still taken as 8.5 x 12 inches.
> I used this code for changing printer
> Printer.PrinterIndex:=0;
> Which is the correct way of changing the printer?
This is the correct way but there is a bug in the Printers unit (i don't
know which exactly) which sometimes lets it pick up the properties of the
default printer instead of the one you select.
Try this as workaround:
Var
Device : array[0..255] of char;
Driver : array[0..255] of char;
Port : array[0..255] of char;
hDeviceMode: THandle;
begin
Printer.PrinterIndex := 0;
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
Printer.SetPrinter(Device, Driver, Port, 0 );
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
The SetPrinter statement should force a complete reload of the printers
TDeviceMode record.
Peter Below (TeamB) 100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!