Home Devices
New Blog Posts: Merging Reports - Part 1 and Part 2

Accessing Default printer settings

edited July 2009 in Devices
Hello,

RB 11.02 + Delphi 7

I know it was discussed couple of times and there is even a Tech Tip
regarding working with default printer, but I can't get it to work.

I want to read default printer settings (duplex and orientation) and assign
them to my report.PrinterSettings before printing.

To test it, in Windows/Control Panel I have set my default printer
orientation to Landscape. Wherever I access the Printer Properties dialog
(i.e. in MS Word) it displays Landscape as selected, correctly.

I made a simple test application, one form, a label and a button on it.

code:
------------------
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms, Dialogs, ppPrintr, StdCtrls;

type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
defPrinter: TppPrinter;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
defPrinter := TppPrinter.Create;
defPrinter.PrinterName := ppPrinters.DefaultPrinterName;

label1.Caption := defPrinter.PrinterName;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
defPrinter.PrinterSetup.EditDeviceSettings;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
defPrinter.Free;
end;
------------------
end of code.

When I click on the button, the printer properties dialog displays, but the
Orientation setting is set to Portrait. But, when I change the paper size
(in Windows), it is also changed in the application. So, I can see paper
zies change, but not Orientation. I can't test duplex setting at this
point, because my local printer does not support duplex, but I want to
controll it as well.

What am I doing wrong?

Thanks,
Jerry

Comments

  • edited July 2009
    I think I found the solution...

    after assigning
    defPrinter.PrinterName := ppPrinters.DefaultPrinterName;
    I added
    defPrinter.PrinterSetup := defPrinter.DefaultPrinterSetup;

    There is no help on DefaultPrinterSetup either in RBUILDER.HLP file or your
    wiki page.
    Is my solution the correct way to solve this problem?

    Thanks,
    Jerry

This discussion has been closed.