Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/VCL/Dialog Controls/TPrinterSetupDialog    [ Add a report in this area ]  
Report #:  68179   Status: Closed
Printer dialogs always switches to the default printer
Project:  Delphi Build #:  3168
Version:    12.0 Submitted By:   Finn Tolderlund
Report Type:  Basic functionality failure Date Reported:  10/22/2008 9:24:53 AM
Severity:    Serious / Highly visible problem Last Updated: 7/22/2009 10:36:14 PM
Platform:    All platforms Internal Tracking #:  
Resolution: Duplicate  Resolved in Build: : None
Duplicate of:  67694
Voting and Rating
Overall Rating: (1 Total Rating)
1.00 out of 5
Total Votes: 5
Description
The printer dialogs TPrintDialog and TrinterSetupDialog always show the default printer each time the dialog is shown.
They should show the current selected printer from Printer.PrinterIndex.
But instead the dialogs always switches to the default printer.
Steps to Reproduce:
Delphi 2009
Create a new VCL forms application.
Put a Button,  a Label and a PrinterSetupDialog on the form.
Write this code and run the application.

uses
  Printers;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if PrinterSetupDialog1.Execute then
    Label1.Caption := Printer.Printers[Printer.PrinterIndex];
  if PrinterSetupDialog1.Execute then
    Label1.Caption := Printer.Printers[Printer.PrinterIndex];
end;

Actual behaviour:
The dialog always shows the default printer each time the printer dialog is
executed.
TPrintDialog does the same.

Expected behaviour:
The printer you select in the first Execute should automatically be shown in
the second Execute of the printer dialog.
It does so in Delphi 7.

Workarounds
None
Attachment
None
Comments

Pasquale Rubano at 10/22/2008 11:44:42 PM -
Tim,
your problem is also the mine.
I've submitted the problem by several days, but CodeGear do not answer. There is a serious bug to the Delphi 2009 compiler may be. I don't know how can I do: I'm blocked with migration from D7 to D2009.
Regards
   Pasquale Rubano
   prubano@studiorubano.it

Hexard Inc. Director at 11/26/2008 7:11:44 PM -
This problem occurs for the bug of the GetPrinter function of Dialogs.pas. Each offset of the DEVNAMES structure body has to appoint it by a letter unit, but becomes the byte unit here. I become a right value if I divide the value of these offsets by SizeOf(char).

This prose is a thing by the machine translation. The careless part please forgive it.

Finn Tolderlund at 12/14/2008 7:01:29 AM -
A possible fix:
In Dialogs.pas add 3 lines:

{code}
      with DevNames^ do
      begin
        wDriverOffset := Longint(Offset) - Longint(DevNames);
wDriverOffset := wDriverOffset div SizeOf(Char);  //add
        Offset := StrECopy(Offset, Driver) + 1;
        wDeviceOffset := Longint(Offset) - Longint(DevNames);
wDeviceOffset := wDeviceOffset div SizeOf(Char);  //add
        Offset := StrECopy(Offset, Device) + 1;
        wOutputOffset := Longint(Offset) - Longint(DevNames);;
wOutputOffset := wOutputOffset div SizeOf(Char);  //add
        StrCopy(Offset, Port);
      end;
{code}

It seems to work, but I don't know if it has any nasty side effects.

Server Response from: ETNACODE01