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

Archive Reader - Print from Database

edited July 2006 in General
All

I have a table, one of the fields holds a raf file from which I want to
print a range of records.

When the first record is displayed I want to ask the printer to use, when
printing subsequent records I want to supress the print dialog and use the
printer selected for the first document.

The following code is almost there but I can not capture the selected
printer, the line "DBArchiveReader.Printer.PrinterName" always returns to
the default printer. How do I capture the actual printer selected?

Any advice will be greatfully received.

Thanks in advance

Philip L Jackson

Env Delphi 6. Ent Rbuilder 9.

MyCopies := StrToInt(edtCopies.Text);
for j := 1 to k do
begin
DBArchiveReader.Reset;
DBArchiveReader.Printer.PrinterSetup.Copies := MyCopies;
if j > 1 then
begin
DBArchiveReader.PrinterSetup.PrinterName := MyPrinter;
DBArchiveReader.PrinterSetup.Copies := MyCopies;
end;
MainDataModule.ppReport1.ShowAutoSearchDialog := FALSE;

DBArchiveReader.DatabaseSettings.Name :=
winInvCopy.InvoiceTable.FieldByName('INVOICE_NO').AsString;
DBArchiveReader.DeviceType := 'dtPrinter';
ppviewer1.report := DBArchiveReader;
ppviewer1.RegenerateReport;

ppViewer1.Print;

MyPrinter :=DBArchiveReader.Printer.PrinterName;
MyCopies :=DBArchiveReader.Printer.PrinterSetup.Copies;

DBArchiveReader.ShowPrintDialog := FALSE;

if winInvCopy.CopyGroup.ItemIndex = 1 then
winInvCopy.InvoiceTable.Next;
end;

Comments

  • edited August 2006
    Hi Philip,

    Try accessing the printer object of the print dialog after it closes. For
    instance...

    uses
    ppPrintr;

    procedure TForm1.ppArchiveReader1PrintDialogClose(Sender: TObject);
    begin
    ShowMessage(TppPrinter(ppArchiveReader1.PrintDialog.Printer).PrinterName);
    end;

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited August 2006
    Hi Nico

    This now works well for the printer, MyPrinter is now set to the correct
    printer when the table is on the 2nd and subsequent records, however I am
    still having trouble with the number of copies.

    In the code below, although MyCopies is set to 2, the
    'DBArchiveReader.Printer.PrinterSetup.Copies' refuses to change from the
    Printer default (1 copy) so I get 2 copies of the first document (as
    required) but only 1 copy of subsequent documents.

    Any ideas?

    Thanks in advance

    Philip L Jackson


    for j := 1 to k do
    begin
    DBArchiveReader.Reset;
    DBArchiveReader.Printer.PrinterSetup.Copies :=
    MyCopies;
    if j > 1 then DBArchiveReader.PrinterSetup.PrinterName :=
    MyPrinter;

    MainDataModule.ppReport1.ShowAutoSearchDialog := FALSE;

    DBArchiveReader.DatabaseSettings.Name :=
    winInvCopy.InvoiceTable.FieldByName('INVOICE_NO').AsString;
    DBArchiveReader.DeviceType := 'dtPrinter';

    ppviewer1.report := DBArchiveReader;
    ppviewer1.RegenerateReport;

    ppViewer1.Print;

    DBArchiveReader.ShowPrintDialog := FALSE;

    if winInvCopy.CopyGroup.ItemIndex = 1 then
    winInvCopy.InvoiceTable.Next;
    end;


    procedure TwinInvRB.DBArchiveReaderPrintDialogClose(Sender: TObject);
    begin
    MyPrinter :=
    TppPrinter(DBArchiveReader.PrintDialog.Printer).PrinterName;
    MyCopies :=
    TppPrinter(DBArchiveReader.PrintDialog.Printer).PrinterSetup.Copies;

    end;




  • edited August 2006
    Hi Philip,

    Sorry, I forgot to mention that when setting the PrinterSetup of an archive
    file, you need to use the OnInitializePrinterSetup event to do so.

    --
    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.