Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Delphi 5 / QuickReport 3.0.5: TPrinterSetupDialog -> QRPrinterSettings ??

2,021 views
Skip to first unread message

Jack N.A. Bakker

unread,
May 29, 2000, 3:00:00 AM5/29/00
to
How do you copy the printer settings a specified by a user from a
TPrinterSetupDialog (or from the default printer) to the QRPrinterSettings
of a QuickReport?

Is there an easy way, or do you have to make assignment statements to do
this, like:

MyReport.PrinterSettings.Copies := Printer.Copies;
etc. ??

Thanks in advance,

Jack


Stefan Buynov

unread,
May 30, 2000, 3:00:00 AM5/30/00
to
Hi Jack,
I don't know about an easier way, but to set
YourReport.QRPrinter.printersettings.*.

"Jack N.A. Bakker" <JA...@no.spam.RULLF2.LeidenUniv.NL> wrote in message
news:8gucg1$oi...@bornews.borland.com...

Colin Acheson

unread,
May 30, 2000, 3:00:00 AM5/30/00
to
I think it's easier than that. Just assign the printer index and QR
should use whatever settings you have set for that printer. e.g.

MyReport.PrinterSettings.PrinterIndex := Printer.PrinterIndex;

Jack N.A. Bakker

unread,
May 30, 2000, 3:00:00 AM5/30/00
to
Colin,

This does not seem to work, the way you propose:

I now have the following lines in my MyReport.BeforePrint event:

PrinterSetupDialog1.Execute;
MyReport.PrinterSettings.PrinterIndex := Printer.PrinterIndex;
and this does not work: When I change the printer settings, the report still
gets printed using the default settings.

Any other ideas?

TIA!

Jack


<no direct mail please (Colin Acheson)> wrote in message
news:3933b036...@newsgroups.borland.com...

Stephane Veillette

unread,
May 30, 2000, 3:00:00 AM5/30/00
to
> MyReport.PrinterSettings.PrinterIndex := Printer.PrinterIndex;

It doesn't work. I always got the same error "printer out of range".

Any Idea?

Stephane

Stefan Buynov

unread,
May 31, 2000, 3:00:00 AM5/31/00
to
I read in the newsgroup that there is a problem with setting the
printerindex with the standard print preview (and the standard printersetup
dialog).
I don't have such kind of problems - I made my custom preview and my advice
to you is to make your custom preview - there's a very useful demo on the
QuSoft download page: the filename is QR3CSTD3.ZIP. I downloaded this demo
and put a standard PrintDialog on the preview form. Then I wrote the
following code for the PrintButton on the preview form:

procedure TfrmQRepPreview.PrintButtonClick(Sender: TObject);
begin
with PrintDialog do
begin
FromPage := 1;
ToPage := QRUserPreview.QRPrinter.PageCount;
MinPage := 1;
MaxPage := QRUserPreview.QRPrinter.PageCount;
end;
if PrintDialog.Execute then
with PrintDialog do
// for the Quickrep print
If QRUserPreview.QRPrinter.Master is TQuickRep then
with TQuickRep(QRUserPreview.QRPrinter.Master) do
begin
printersettings.FirstPage := FromPage;
printersettings.LastPage := ToPage;
printersettings.Copies := Copies;
Printersettings.PrinterIndex := Printers.Printer.PrinterIndex;
QRUserPreview.QRPrinter.Print
end
else
// for the CompositeReport print
with TQRPatch(QRUserPreview.QRPrinter.Master).ParentReport do
begin
printersettings.FirstPage := FromPage;
printersettings.LastPage := ToPage;
printersettings.Copies := Copies;
Printersettings.PrinterIndex := Printers.Printer.PrinterIndex;
QRUserPreview.QRPrinter.Print
end;
end;

Everything works fine. You can try.
Regards,
Stefan

"Stephane Veillette" <veill...@biotonix.com> wrote in message
news:8h16os$lb...@bornews.borland.com...

Colin Acheson

unread,
May 31, 2000, 3:00:00 AM5/31/00
to
Strange. It always works for me. Admittedly I haven't tried
changing number of copies but certainly selecting printers has never
been a problem (except using Delphi 3 on NT with certain printers -
see my reply below to Stephane). Try the following minor change to
your code: (Note the "if")

if PrinterSetupDialog1.Execute then
MyReport.PrinterSettings.PrinterIndex := Printer.PrinterIndex;

Regards,
Colin Acheson

Colin Acheson

unread,
May 31, 2000, 3:00:00 AM5/31/00
to
If you are selecting a valid printer and assigning a valid printer
index it should always work. However there is a problem with Delphi
3 on Windows NT with certain network printers. We had a discussion
about it here some time back.

There is a bug in the D3 printers unit where, when you select another
printer, it sometimes does not return the chosen printer's correct
index. Instead it adds that printers name again to the end of the
printer list and returns an invalid index.

The error is at approx. line 411 of Printers.pas in the following
function:

function TPrinterDevice.IsEqual(ADriver, ADevice, APort: PChar):
Boolean;

The function is a one-liner. In Delphi 3, it is:

Result := (Device = ADevice) and (Port = APort);

This should be replaced with the Delphi 5 equivalent, which is:

Result := (Device = ADevice) and ((Port = '') or (Port = APort));

Regards,
Colin Acheson

Stephane Veillette

unread,
May 31, 2000, 3:00:00 AM5/31/00
to
hi,

is there a way in Delphi 5 to change the windows default printer???

I've looked in the help files but I can't find anything.

Maybe it's the better way to correct the bug.
Stephane


<no direct mail please (Colin Acheson)> wrote in message

news:3934e0b9...@newsgroups.borland.com...

Colin Acheson

unread,
Jun 1, 2000, 3:00:00 AM6/1/00
to
Stephane,

See also my second reply to Jack.

Colin Acheson

unread,
Jun 1, 2000, 3:00:00 AM6/1/00
to
Jack,

As it is not working for either you or Stephane but is reliable for
me, the problem must relate to the point in time at which you are
assigning the PrinterIndex to the report's PrinterSettings.

It needs to be after the report form is created yet before it is
previewed or printed. On the face of it, the BeforePrint event would
seem to be a good place but perhaps it is too late.

I always create my report forms dynamically, so I put the assignment
code either in the FormCreate method of the form on which the QuickRep
resides or in the calling form as per the following example: (Note
that the QuickRep component is named "Report")

FormBillingRep := TFormBillingRep.Create(nil);
with FormBillingRep do
try
Report.PrinterSettings.PrinterIndex := Printer.PrinterIndex;
Report.Preview; // or Report.Print;
finally
Close;
Free;
end;

As well as freeing the form, you also need some code in the OnClose
event of the form to free the QuickRep itself, eg.

procedure TFormBillingRep.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Report.Free;
end;

Regards,
Colin Acheson

On Tue, 30 May 2000 21:54:30 +0200, "Jack N.A. Bakker"
<JA...@no.spam.RULLF2.LeidenUniv.NL> wrote:

>Colin,
>
>This does not seem to work, the way you propose:
>
>I now have the following lines in my MyReport.BeforePrint event:

<remainder snipped>

Bill Sparrow

unread,
Jun 1, 2000, 3:00:00 AM6/1/00
to
In article <3935c9ca...@newsgroups.borland.com>, (Colin Acheson)
wrote:

> As well as freeing the form, you also need some code in the OnClose
> event of the form to free the QuickRep itself, eg.
>
> procedure TFormBillingRep.FormClose(Sender: TObject;
> var Action: TCloseAction);
> begin
> Report.Free;
> end;

Why do you need this? Surely if the form is the owner of the report, it
will free it when it is, itself, freed?

--Bill Sparrow--

Stephane Veillette

unread,
Jun 2, 2000, 3:00:00 AM6/2/00
to
Hi Colin,

it's working with the current code :

QuickRep.PrinterSettings.PrinterIndex := Printer.PrinterIndex;
QuickRep.PrinterSettings.ApplySettings(QuickRep.Printer);
Thank for you help :)

Stephane

<no direct mail please (Colin Acheson)> wrote in message

news:3935c8e1...@newsgroups.borland.com...


> Stephane,
>
> See also my second reply to Jack.
>

> Regards,
> Colin Acheson
>

Colin Acheson

unread,
Jun 2, 2000, 3:00:00 AM6/2/00
to
Thanks, Stephane and Jorrit. I will put the "ApplySettings" line in
my code too as a precaution.

Regards,
Colin Acheson

Message has been deleted

Stephane Veillette

unread,
Jun 5, 2000, 3:00:00 AM6/5/00
to
I got a new bug.

It's working fine with one program (OCX) but not in the other, with the same
code for printing.

here's the code:

with PrintDialog1 do
begin
PrintDialog1.FromPage := 1;
PrintDialog1.ToPage := QuickRep.PageNumber;
PrintDialog1.MaxPage := QuickRep.PageNumber;

if Execute = true then
begin
QuickRep.PrinterSettings.FirstPage := FromPage;
QuickRep.PrinterSettings.LastPage := ToPage;
QuickRep.PrinterSettings.Copies := Copies;

QuickRep.PrinterSettings.PrinterIndex := Printer.PrinterIndex;
QuickRep.PrinterSettings.ApplySettings(QuickRep.Printer);
end;
end;

The problem comes from the Printer object. Before the Execute call,
Printer.PrintIndex is correctly set. The print dialog sets the printer to an
invalid index when you click on "ok" to print. It's why I always have this
error: "Printer index out of range".

Any Idea?

Should I need to create my own Print Dialog?

Stephane

<no direct mail please (Colin Acheson)> wrote in message

news:39384020...@newsgroups.borland.com...

Colin Acheson

unread,
Jun 6, 2000, 3:00:00 AM6/6/00
to
Stephane,

If you are using Delphi3 on Windows NT, there is a problem in the D3
printers unit that can cause this type of problem. It was cured in
D5. I'm not sure about D4.

When a new printer is selected, Delphi looks for it in the printers
list. If it is found, the printer index is set to that printer.
Otherwise it adds the printer to the end of the list and uses the new
printer index. However with certain network printers on NT, Delphi
was not detecting them in the list and thus adding them again at the
end of the list and returning an invalid index.

To compare the selected printer with those in the list, Delphi 3 used
the following function. It is at approx. line 411 of Printers.pas:

function TPrinterDevice.IsEqual(ADriver, ADevice, APort: PChar):
Boolean;

begin


Result := (Device = ADevice) and (Port = APort);

end;

Try replacing this with the Delphi 5 equivalent, which is:

Result := (Device = ADevice) and ((Port = '') or (Port = APort));

Also note there is a memory leak in the D3 printers unit.

Before the last line "Inherited Destroy;" in TPrinter.Destroy, insert
the following:

if DeviceMode <> 0 then
begin
GlobalUnlock(DeviceMode);
GlobalFree(DeviceMode);
DeviceMode := 0;
end;

Regards,
Colin Acheson

On Mon, 5 Jun 2000 12:32:48 -0400, "Stephane Veillette"
<veill...@biotonix.com> wrote:

>I got a new bug.

<snip>

Stefan Buynov

unread,
Jun 6, 2000, 3:00:00 AM6/6/00
to
Stephane,
Try this line
QuickRep.PrinterSettings.PrinterIndex := PRINTERS.Printer.PrinterIndex;

This way you will tell Delphi exclusively that you want to use the global
variable printer from the printers unit.
I remember I had a problem similar to yours and I think that this change
solve it.
Regards,
Stefan


"Stephane Veillette" <veill...@biotonix.com> wrote in message

news:8hgkjc$f1...@bornews.borland.com...


> I got a new bug.
>

> It's working fine with one program (OCX) but not in the other, with the
same
> code for printing.
>
> here's the code:
>
> with PrintDialog1 do
> begin
> PrintDialog1.FromPage := 1;
> PrintDialog1.ToPage := QuickRep.PageNumber;
> PrintDialog1.MaxPage := QuickRep.PageNumber;
>
> if Execute = true then
> begin
> QuickRep.PrinterSettings.FirstPage := FromPage;
> QuickRep.PrinterSettings.LastPage := ToPage;
> QuickRep.PrinterSettings.Copies := Copies;
>
> QuickRep.PrinterSettings.PrinterIndex := Printer.PrinterIndex;
> QuickRep.PrinterSettings.ApplySettings(QuickRep.Printer);
> end;
> end;
>

> The problem comes from the Printer object. Before the Execute call,
> Printer.PrintIndex is correctly set. The print dialog sets the printer to
an
> invalid index when you click on "ok" to print. It's why I always have
this
> error: "Printer index out of range".
>

> Any Idea?
>
> Should I need to create my own Print Dialog?
>
> Stephane
>
>
>
> <no direct mail please (Colin Acheson)> wrote in message
> news:39384020...@newsgroups.borland.com...
> > Thanks, Stephane and Jorrit. I will put the "ApplySettings" line in
> > my code too as a precaution.
> >
> > Regards,
> > Colin Acheson
> >

Stephane Veillette

unread,
Jun 6, 2000, 3:00:00 AM6/6/00
to
Hi Stefan,

I already tried this without success.

Everything is ok now. I just create my own PrintDialog. It's the best
solution :)

Thanks to you and Colin

Regards,
Stephane


Stefan Buynov <bou...@yahoo.com> wrote in message
news:8hi765$31...@bornews.borland.com...

Bill Sparrow

unread,
Jun 7, 2000, 3:00:00 AM6/7/00
to

kgu...@spk.gov.tr

unread,
Jun 22, 2000, 3:00:00 AM6/22/00
to

It does not work.
in delphi 3 and its quickreport

In article <3934e0b9...@newsgroups.borland.com>,


(no direct mail please) (Colin Acheson) wrote:
> If you are selecting a valid printer and assigning a valid printer
> index it should always work. However there is a problem with Delphi
> 3 on Windows NT with certain network printers. We had a discussion
> about it here some time back.
>
> There is a bug in the D3 printers unit where, when you select another
> printer, it sometimes does not return the chosen printer's correct
> index. Instead it adds that printers name again to the end of the
> printer list and returns an invalid index.
>

> The error is at approx. line 411 of Printers.pas in the following
> function:


>
> function TPrinterDevice.IsEqual(ADriver, ADevice, APort: PChar):
> Boolean;
>

> The function is a one-liner. In Delphi 3, it is:
>
> Result := (Device = ADevice) and (Port = APort);
>

> This should be replaced with the Delphi 5 equivalent, which is:


>
> Result := (Device = ADevice) and ((Port = '') or (Port = APort));
>

> Regards,
> Colin Acheson


>
> On Tue, 30 May 2000 16:04:42 -0400, "Stephane Veillette"
> <veill...@biotonix.com> wrote:
>
> >> MyReport.PrinterSettings.PrinterIndex := Printer.PrinterIndex;
> >

> >It doesn't work. I always got the same error "printer out of range".
> >
> >Any Idea?
> >
> >Stephane
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.

kgu...@spk.gov.tr

unread,
Jun 23, 2000, 3:00:00 AM6/23/00
to
I was using delphi 3 with quickreport 2.0g when I got printer index out
of range error in reports.This error emerged in windows 2000.In windows
95 everything was fine.I tried the proposed solutions that I have found
on the deja forums.But it did not help.Then I downloaded the
quickreport 2.0K version.Now everthing is ok.
0 new messages