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

Error in ppPDlg

edited September 2004 in General
Hi,
I think that is error in unit ppPDlg in procedure
TppPrintDialog.InitializePrinterControls;

When no printer is installed on computer or Spooler service is stopped,
Access violation
error is shown when button Print is clicked in preview. Error is in this
condition:
if (FPrinter = nil) or (FPrinter.PrinterSetup.PrinterNames.Count = 0) then
Right condition is that:
if (FPrinter = nil) or (FPrinter.PrinterSetup.PrinterNames.Count = 0) or
// I have no printer, but I have in printer dialog => without
this I get access violation error
((cbxPrinters.Items.Count = 1) and
(cbxPrinters.Items.IndexOf(cDefault)<>-1)) then

Regards
Roman Krupicka

Comments

  • edited September 2004
    Hi Roman,

    Thanks for the feedback. This was an issue in ReportBuilder 6.x and has
    been addressed in RB 7.x by adding the Screen device as a printer when no
    printers are installed on a computer. This automatically assigns the
    Default printer to the Screen rather than causing an AV.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited September 2004
    Hi,
    I have RB 7.04 for Delphi 5. Screen printer doesn't solve this error.

    1. Stop Spooler
    2. Show preview on screen - it is OK.
    3. Click on Print button - you can see AV....

    Regards
    Roman Krupicka


  • edited September 2004
    Hi Roman,

    In my testing with RB 7.04 and Delphi 5, printing from the preview with no
    printers installed on my computer throws an exception claiming that it is
    not possible to print using the screen device. This is purely an
    informative message and is not an AV error. If you take a look in the
    ppPrintr.pas file at the TppPrinterList.GetSystemDefaultPrinterName
    function, you will see that when there are no printers installed on your
    machine, the default is set to Screen.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited October 2004
    Hi Nico,
    it is very strange... I tried to make pure new application with TppReport
    component only.
    I didn't change any settings, I put TppLabel on Detail band only.
    I stopped spooler, run app and clicked on button -> ppReport1.Print. OK -
    preview was
    shown without any problems, but after clicking on Print button in left upper
    corner,
    I got AV fault...

    Win2000 SP4, RB 7.04, Delphi 5 Update pack 1

    Regards
    Roman

    **********************************************************
    unit Unit1;

    interface

    uses
    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    StdCtrls, ppPrnabl, ppClass, ppCtrls, ppBands, ppCache, ppComm, ppRelatv,
    ppProd, ppReport;

    type
    TForm1 = class(TForm)
    ppReport1: TppReport;
    ppHeaderBand1: TppHeaderBand;
    ppDetailBand1: TppDetailBand;
    ppFooterBand1: TppFooterBand;
    ppLabel1: TppLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.DFM}

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    ppReport1.Print;
    end;

    end.

    **********************************************************

  • edited October 2004
    Hi Roman,

    What does the AV message say? Are you able to trace into the RB code after
    the AV error occurs? Try setting your Delphi IDE to stop on exceptions and
    see if you can do so.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited October 2004
    Hi Nico,
    message is: AV at address 04AD115 in module 'Project1.exe'. Read of address
    0000001D.
    Problem is in unit ppPDlg in procedure InitializePrinterControls. Look at
    rows with ******.

    Regards
    Roman

    procedure TppPrintDialog.InitializePrinterControls;
    var
    liIndex: Integer;
    begin

    cbxPrinters.Items.Assign(FPrinter.PrinterSetup.PrinterNames);

    {remove 'screen' from printer names option}
    liIndex := cbxPrinters.Items.IndexOf(cScreen);
    cbxPrinters.Items.Delete(liIndex);

    if (FPrinter = nil) or (FPrinter.PrinterSetup.PrinterNames.Count = 0)
    ***************************************************
    // >>> this condition is necessary for avoid to AV <<<
    // or ((cbxPrinters.Items.Count = 1) and
    (cbxPrinters.Items.IndexOf(cDefault)<>-1))
    ***************************************************
    then
    begin
    cbxPrinters.Visible := False;
    btnPrinterProperties.Visible := False;
    lblNoPrintersInstalled.Visible := True;

    {display caption, 'There are no printers currently connected to your
    computer'}
    lblNoPrintersInstalled.Caption := ppLoadStr(8);
    end
    else
    begin
    for liIndex := 0 to cbxPrinters.Items.Count - 1 do
    begin
    ******************************************************
    // >>> AV is shown on this condition <<<
    if (ppPrinters.PrinterInfo[cbxPrinters.Items[liIndex]].IsLocal)
    then
    ******************************************************
    cbxPrinters.Items.Objects[liIndex] := TObject(0)
    else
    cbxPrinters.Items.Objects[liIndex] := TObject(1);
    end;
    cbxPrinters.Sorted := True;
    cbxPrinters.ItemIndex :=
    cbxPrinters.Items.IndexOf(FPrinter.PrinterSetup.PrinterName);
    if cbxPrinters.ItemIndex = -1 then
    begin
    FPrinter.PrinterSetup.PrinterName := cbxPrinters.Items[0];
    cbxPrinters.ItemIndex := 0;
    end;
    end;
    UpdatePrinterSettings;
    end; {procedure, InitializePrinterControls}




  • edited October 2004
    Hi Roman,

    I am still unable to recreate this error. I have traced through the code
    you mentioned and everything seemed to work correctly. Is there something
    else I'm missing here? When you say that you stop the spooler, are you
    pausing the print job from the Windows Printer dialog? What is the purpose
    of this?

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited October 2004
    Hi Nico,
    stop spooler = stop Spooler service (net stop Spooler /Y).
    I try to emulate PC without printers. I want to print to file
    without any printer, but I get AV fault.

    I use TExtraDevices for Delphi, version 2.8.

    **********************************************
    I tried to debug that code and here are my findings:
    **********************************************
    if (FPrinter = nil) or (FPrinter.PrinterSetup.PrinterNames.Count = 0)
    =========================================
    FPrinter.FPrinterName = 'Screen'
    FPrinter.PrinterSetup.PrinterNames.Count = 2 ([0] = 'Default', [1] =
    'Screen')
    **********************************************
    else
    begin
    for liIndex := 0 to cbxPrinters.Items.Count - 1 do
    begin
    if (ppPrinters.PrinterInfo[cbxPrinters.Items[liIndex]].IsLocal)
    then
    cbxPrinters.Items.Objects[liIndex] := TObject(0)
    else
    cbxPrinters.Items.Objects[liIndex] := TObject(1);
    end;

    =========================================
    ppPrinters.PrinterInfo['Default'] = nil !!!!! AV Fault !!!!!

    ppPrinters.PrinterInfo['Screen'] <> nil
    -> it is OK, but at start of InitializePrinterControls procedure is this
    code:

    {remove 'screen' from printer names option}
    liIndex := cbxPrinters.Items.IndexOf(cScreen);
    cbxPrinters.Items.Delete(liIndex);
    **********************************************

    Regards
    Roman


  • edited October 2004
    Hi Roman,


    What is the purpose of doing this? Are you trying to export to a different
    format using TExtraDevices? Are you trying to print to a PRN file? I am
    unclear why or how you would like to print a report without a printer
    installed. Your debug information makes sense but I still am unable to
    recreate the AV. Where are you setting the default device to nil?

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited October 2004
    Hi Nico,
    some of our customers haven't installed any printer on their computer.
    I know it is strange:-), but they exist. And they want to print to file
    (for example PDF) and send result by e-mail. I try to emulate their system.
    We use TExtraDevices for printing to file.
    I set the default device to nil nowhere. In my simple app, I put component
    on the form only, put one TppLabel on detail band and print. It's all.

    Regards
    Roman

  • edited October 2004
    Hi Roman,

    If you are printing to file, the device selected in the printer drop down
    should not matter. Once you select the Print to File option on the Print
    Dialog, this becomes irrelevant. Are your customers getting an AV when they
    try to print to file with no printer installed? Be sure you have the
    AllowPrintToFile property set to True on the report. This will give you the
    extra print to file options in the print dialog and then allow your
    customers to print to an exported file type.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.