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

Cannot Print To Device

edited January 2005 in General
For Some Reason I cannot print to anything but the screen. Not To Printers,
Not to Archives, not to a PDF.

for example If I do:

Report.DeviceType := dtPrinter;
Report.Print;

Up pops the Preview Form

Report.DeviceType := 'Printer';
Report.Print;

Still does not work.

Tracing through the code I discover that the TppProducer.Transfer Method is
called twice.

The First time it is called lSourceProducer.FDeviceType = 'Printer'

The second time through lSourceProducer.FDeviceType = 'Screen'

I am not sure what is going on here but I could not find any place where a
Device Type is being set equal to anything other than in the write method
when I set the Property in code?

Does anyone have any ideas? This is starting to become extreemly
frustrating and annoying.

Comments

  • edited January 2005
    Hello,

    The Transfer method fires when you are loading a template into a report
    object. If you are trying to change the default device type of a template,
    you will need to use the Template events to do so (most likely the OnLoadEnd
    event). See the article below for more information.


    ----------------------------------------------
    Tech Tip: Using Template Events
    ----------------------------------------------

    The Report.Template object has several events that can be used for
    customizing what happens when a report is loaded or saved:

    - OnLoadStart
    - OnLoadEnd
    - OnNew
    - OnSaveStart
    - OnSaveEnd


    The OnLoadEnd and OnNew events are often used to perform actions related to
    report and data initialization.

    The OnSaveEnd event is often used to save additional descriptive ("meta")
    data to the database each time the report is saved.

    Example:

    The Report.Template events are public and therefore must be assigned at
    run-time.


    1. In the private section of your form declaration you can declare an
    event-handler method:

    TForm = class(TForm)
    private
    procedure myTemplateOnLoadEndEvent(Sender: TObject);

    public

    end;


    2. In the Form.OnCreate event, you can assign the event-handler to the
    event:

    procedure TForm1.FormCreate(Sender: TObject);
    begin

    ppReport1.Template.OnLoadEnd := myTemplateOnLoadEndEvent;

    end;


    3. Implement the event-handler method:

    procedure TForm1.myTemplateOnLoadEndEvent(Sender: TObject);
    begin

    {add code here to initialize the report or data, etc. }
    ppReport1.PrinterSetup.MarginTop := 0.5;

    end;

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited January 2005
    Perfect. Worked Like A Charm.

    Thanks.

This discussion has been closed.