Board index » delphi » QR3 - Printer settings from Printer setup

QR3 - Printer settings from Printer setup

I am doing a qrep1.preview and want to use the printer setup button to limit
the number of pages printed
ie in preview click on printer setup
modify pages range
then click on print

I t just ignores me
Am I doing something stupid
?
Tanks
Jenny

--

 

Re:QR3 - Printer settings from Printer setup


On Mon, 21 May 2001 17:25:22 +0200, "Jenny" <madetomeas...@mweb.co.za>
wrote:

Quote
>I am doing a qrep1.preview and want to use the printer setup button to limit
>the number of pages printed
>ie in preview click on printer setup
>modify pages range
>then click on print

>I t just ignores me
>Am I doing something stupid

Probably not.   The problem has been reported before.    However I
just tested it with Delphi 5 and QR2.0K and it worked OK for me.   My
report was 137 pages long but I used the printer setup dialog from the
preview to select 2 copies of pages 2 to 3.   When I then clicked the
print button, that is what it printed.   However the slow movement of
the progress bar indicated that it ran through the entire report
before printing just the selected pages.

What versions of Delphi and QR are you using?  

When selecting the pages, did you also change the selected printer?  

Does the same thing happen if you don't change the printer?  

The reason I ask the above questions is that there was a bug in the
printers.pas unit of Delphi 2.   I think it was still there in Delphi
3 but must have been fixed now because I am no longer incorporating
the patch for it in my copy of Delphi 5.  The following is a
description of the problem and patch as posted on 10th September 1997
by Pascal Bochoridis.   Note that he mentions number of copies but I
think it also affected page selection for printing.   Sorry, the post
is rather long although I snipped some of it:

regards
Colin Acheson

(Reposted article by Pascal Bochoridis):

Have you tried setting multiple copies in QuickReport.PrintSettings
and only one copy comes out of your printer?

If yes, then this is the solution.

I have an application that prints to 2 different printers.
The one is a dot-matrix , the other is a laser.
The report that goes to the laser has QuickReport.PrintSettings.Copies
= 3

I noticed that when the dot - matrix is set as the default printer,
then only 1 copy comes out from the laser instead of 3.
When the laser is default then it prints the 3 copies as it is right.

I first thought that this is an error in QuickReport 2.
I have become a registered user and acquired the source code.

I added a copy of QRPRNTR in my project. This way I could experiment
debugging the code (Compiler debug ON)

After debugging I pinpointed then problem by setting

    DevMode := GlobalLock(DeviceMode);

    ShowMessage('TPrinterSettings.GetPrinterSettings GPrinter'#13 +
                'Device: ' + FDevice + #13 +
                'DeviceMode:' + IntToStr(DeviceMode) + #13 +
          'MultipleCopies:'+ IntToStr(DevMode^.dmCopies) + ' ' +
iif(Supported(dm_copies), 'SUPPORTED', 'NOT SUPPORTED') + #13 +
                #13 +
                'FPrinter.PrinterIndex: ' +
IntToStr(FPrinter.PrinterIndex) +
#13 +
                'Capabilities[' + iif(pcCopies in
FPrinter.Capabilities,
'pcCopies,', '') +
                                  iif(pcOrientation in
FPrinter.Capabilities,
'pcOrientation,', '') +
                                  iif(pcCollation in
FPrinter.Capabilities,
'pcCollation,', '') + ']');

in method TPrinterSettings.GetPrinterSettings, procedure GPrinter in
QRPRNTR.PAS
The ShowMessage displayed the SAME DEVICEMODE Address,
when I changed from the default printer to another printer,
with QuickReport.PrinterSettings.PrinterIndex := (Another Printer No)

That means that when you change the PrinterIndex, the settings of the
PREVIOUS default printer are still in action instead of acquiring new
values.

In my case, my dot-matrix does not have multiple copies capability
It has FPrinter.Capabilities = [cpOrientation]

The laser has FPrinter.Capabilities = [cpCopies,
cpOrientation,cpCollate]).

Because of the SAME DEVICEMODE bug, when the dot-matrix was default
the laser was "transformed" to a dot-matrix, that is
it showed FPrinter.Capabilities = [cpOrientation] and thus couldn't
print multiple copies.

I added a copy of PRINTERS.PAS in my projects in order to debug that
too. I noticed that in method
procedure TPrinter.SetToDefaultPrinter;
var
  I: Integer;
  DefaultPrinter: array[0..79] of Char;
  Cur, Device: PChar;
begin
  GetProfileString('windows', 'device', '', DefaultPrinter,
    SizeOf(DefaultPrinter) - 1);
  Cur := DefaultPrinter;
  Device := FetchStr(Cur);
  with Printers do
    for I := 0 to Count-1 do
    begin
      if TPrinterDevice(Objects[I]).Device = Device then
      begin
        with TPrinterDevice(Objects[I]) do

          {***********************************************************
           SetPrinter passes 0 as DeviceMode (Fouth parameter)
            causing the deallocation and allocation of a new
DeviceMode
          ***********************************************************}

          SetPrinter(PChar(Device), PChar(Driver), PChar(Port), 0);
        Exit;
      end;
    end;
  RaiseError(SNoDefaultPrinter);
end;

In method

procedure TPrinter.SetPrinterIndex(Value: Integer);
begin
  CheckPrinting(False);
  if (Value = -1) or (PrinterIndex = -1) then SetToDefaultPrinter
  else if (Value < 0) or (Value >= Printers.Count) then
RaiseError(SPrinterIndexError);
  {*************************** PROBLEM!!!! *************************
   When Value is <> -1 that is when we set the PrinterIndex to 1,2 etc
   SetPrinter DOES NOT EXECUTE and the DEVICEMODE remains FROM THE
PREVIOUS
   SELECTED PRINTER causing the above problems
   *************************** PROBLEM!!!! *************************}
  FPrinterIndex := Value;
  FreeFonts;
  SetState(psNoHandle);
end;

The solution (applies to both registered or non registered users of
QuickReport)

STEP 1 Make a copy of the PRINTERS unit in your projects directory

STEP 2 Add the copy of PRINTERS to your project with the Project
Manager

STEP 3 Edit the SetPrinterIndex method

procedure TPrinter.SetPrinterIndex(Value: Integer);
begin
  CheckPrinting(False);
  if (Value = -1) or (PrinterIndex = -1) then SetToDefaultPrinter
  else if (Value < 0) or (Value >= Printers.Count) then
RaiseError(SPrinterIndexError);
  FPrinterIndex := Value;

  {**************** THIS IS THE NEW CODE ***********************}
  if (FPrinterIndex >= 0) and (FPrinterIndex < Printers.Count) then
  begin
   with Printers, TPrinterDevice(Objects[FPrinterIndex]) do
     SetPrinter(PChar(Device), PChar(Driver), PChar(Port), 0);
  end;
  {*************************************************************}

  FreeFonts;
  SetState(psNoHandle);
end;

STEP 4 Build your project

I did and now my laser prints multiple copies even when the dot-matrix
is default

By the way TDevideMode controls many things
as you can see by it's definition in SOURCE\RTL\WIN\WINDOWS.PAS so the
above correction may solve other unexplained printing problems that I
haven't encountered

Pascalis Bochoridis
Greece

Re:QR3 - Printer settings from Printer setup


Thanks for your reply  - I will look at the code now - it seems complicated
I am using Delphi 4 and QR 3 so would expect the Delphi2 problem to be
sorted out but will apply this solution anyway and see what it does.
No I do not change the printer - I have had problems with that before as
well.

Thanks again
Jenny

--

Quote
Colin Acheson <nomail.please> wrote in message

news:3b0a2c27.8130070@newsgroups.borland.com...
Quote
> On Mon, 21 May 2001 17:25:22 +0200, "Jenny" <madetomeas...@mweb.co.za>
> wrote:

> >I am doing a qrep1.preview and want to use the printer setup button to
limit
> >the number of pages printed
> >ie in preview click on printer setup
> >modify pages range
> >then click on print

> >I t just ignores me
> >Am I doing something stupid

> Probably not.   The problem has been reported before.    However I
> just tested it with Delphi 5 and QR2.0K and it worked OK for me.   My
> report was 137 pages long but I used the printer setup dialog from the
> preview to select 2 copies of pages 2 to 3.   When I then clicked the
> print button, that is what it printed.   However the slow movement of
> the progress bar indicated that it ran through the entire report
> before printing just the selected pages.

> What versions of Delphi and QR are you using?

> When selecting the pages, did you also change the selected printer?

> Does the same thing happen if you don't change the printer?

> The reason I ask the above questions is that there was a bug in the
> printers.pas unit of Delphi 2.   I think it was still there in Delphi
> 3 but must have been fixed now because I am no longer incorporating
> the patch for it in my copy of Delphi 5.  The following is a
> description of the problem and patch as posted on 10th September 1997
> by Pascal Bochoridis.   Note that he mentions number of copies but I
> think it also affected page selection for printing.   Sorry, the post
> is rather long although I snipped some of it:

> regards
> Colin Acheson

> (Reposted article by Pascal Bochoridis):

> Have you tried setting multiple copies in QuickReport.PrintSettings
> and only one copy comes out of your printer?

> If yes, then this is the solution.

> I have an application that prints to 2 different printers.
> The one is a dot-matrix , the other is a laser.
> The report that goes to the laser has QuickReport.PrintSettings.Copies
> = 3

> I noticed that when the dot - matrix is set as the default printer,
> then only 1 copy comes out from the laser instead of 3.
> When the laser is default then it prints the 3 copies as it is right.

> I first thought that this is an error in QuickReport 2.
> I have become a registered user and acquired the source code.

> I added a copy of QRPRNTR in my project. This way I could experiment
> debugging the code (Compiler debug ON)

> After debugging I pinpointed then problem by setting

>     DevMode := GlobalLock(DeviceMode);

>     ShowMessage('TPrinterSettings.GetPrinterSettings GPrinter'#13 +
>                 'Device: ' + FDevice + #13 +
>                 'DeviceMode:' + IntToStr(DeviceMode) + #13 +
>           'MultipleCopies:'+ IntToStr(DevMode^.dmCopies) + ' ' +
> iif(Supported(dm_copies), 'SUPPORTED', 'NOT SUPPORTED') + #13 +
>                 #13 +
>                 'FPrinter.PrinterIndex: ' +
> IntToStr(FPrinter.PrinterIndex) +
> #13 +
>                 'Capabilities[' + iif(pcCopies in
> FPrinter.Capabilities,
> 'pcCopies,', '') +
>                                   iif(pcOrientation in
> FPrinter.Capabilities,
> 'pcOrientation,', '') +
>                                   iif(pcCollation in
> FPrinter.Capabilities,
> 'pcCollation,', '') + ']');

> in method TPrinterSettings.GetPrinterSettings, procedure GPrinter in
> QRPRNTR.PAS
> The ShowMessage displayed the SAME DEVICEMODE Address,
> when I changed from the default printer to another printer,
> with QuickReport.PrinterSettings.PrinterIndex := (Another Printer No)

> That means that when you change the PrinterIndex, the settings of the
> PREVIOUS default printer are still in action instead of acquiring new
> values.

> In my case, my dot-matrix does not have multiple copies capability
> It has FPrinter.Capabilities = [cpOrientation]

> The laser has FPrinter.Capabilities = [cpCopies,
> cpOrientation,cpCollate]).

> Because of the SAME DEVICEMODE bug, when the dot-matrix was default
> the laser was "transformed" to a dot-matrix, that is
> it showed FPrinter.Capabilities = [cpOrientation] and thus couldn't
> print multiple copies.

> I added a copy of PRINTERS.PAS in my projects in order to debug that
> too. I noticed that in method
> procedure TPrinter.SetToDefaultPrinter;
> var
>   I: Integer;
>   DefaultPrinter: array[0..79] of Char;
>   Cur, Device: PChar;
> begin
>   GetProfileString('windows', 'device', '', DefaultPrinter,
>     SizeOf(DefaultPrinter) - 1);
>   Cur := DefaultPrinter;
>   Device := FetchStr(Cur);
>   with Printers do
>     for I := 0 to Count-1 do
>     begin
>       if TPrinterDevice(Objects[I]).Device = Device then
>       begin
>         with TPrinterDevice(Objects[I]) do

>           {***********************************************************
>            SetPrinter passes 0 as DeviceMode (Fouth parameter)
>             causing the deallocation and allocation of a new
> DeviceMode
>           ***********************************************************}

>           SetPrinter(PChar(Device), PChar(Driver), PChar(Port), 0);
>         Exit;
>       end;
>     end;
>   RaiseError(SNoDefaultPrinter);
> end;

> In method

> procedure TPrinter.SetPrinterIndex(Value: Integer);
> begin
>   CheckPrinting(False);
>   if (Value = -1) or (PrinterIndex = -1) then SetToDefaultPrinter
>   else if (Value < 0) or (Value >= Printers.Count) then
> RaiseError(SPrinterIndexError);
>   {*************************** PROBLEM!!!! *************************
>    When Value is <> -1 that is when we set the PrinterIndex to 1,2 etc
>    SetPrinter DOES NOT EXECUTE and the DEVICEMODE remains FROM THE
> PREVIOUS
>    SELECTED PRINTER causing the above problems
>    *************************** PROBLEM!!!! *************************}
>   FPrinterIndex := Value;
>   FreeFonts;
>   SetState(psNoHandle);
> end;

> The solution (applies to both registered or non registered users of
> QuickReport)

> STEP 1 Make a copy of the PRINTERS unit in your projects directory

> STEP 2 Add the copy of PRINTERS to your project with the Project
> Manager

> STEP 3 Edit the SetPrinterIndex method

> procedure TPrinter.SetPrinterIndex(Value: Integer);
> begin
>   CheckPrinting(False);
>   if (Value = -1) or (PrinterIndex = -1) then SetToDefaultPrinter
>   else if (Value < 0) or (Value >= Printers.Count) then
> RaiseError(SPrinterIndexError);
>   FPrinterIndex := Value;

>   {**************** THIS IS THE NEW CODE ***********************}
>   if (FPrinterIndex >= 0) and (FPrinterIndex < Printers.Count) then
>   begin
>    with Printers, TPrinterDevice(Objects[FPrinterIndex]) do
>      SetPrinter(PChar(Device), PChar(Driver), PChar(Port), 0);
>   end;
>   {*************************************************************}

>   FreeFonts;
>   SetState(psNoHandle);
> end;

> STEP 4 Build your project

> I did and now my laser prints multiple copies even when the dot-matrix
> is default

> By the way TDevideMode controls many things
> as you can see by it's definition in SOURCE\RTL\WIN\WINDOWS.PAS so the
> above correction may solve other unexplained printing problems that I
> haven't encountered

> Pascalis Bochoridis
> Greece

Other Threads