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

How to access DrawCommands

edited June 2004 in General
Hello All:

I have a report that I manually extract data from ReportBuilder, then
send to the printer. THIS is done so I can do sophisticated Dot Matrix
printing.

The report is always 1 page.

I need to learn how to access the draw commands associated with this
page. Can anybody show me the code to do this ???


Basically I have been calling PrintToDevices and then manually looping
through the TppDBText components & extracting their text & position.
However, this will not work for a report with a SubReport. Therefore, I need
to dig deeper & get to the Draw commands that are somehow associated with
the TppPage component. Any help would be appreciated. Thank you.


Neil Huhta



PS My current code is below:

Try
Screen.Cursor:=CrHourGlass;
ppReport2.PassSetting:= psTwoPass;
lDevice := TppDevice.Create(fmReport);
lDevice.PageSetting := psLastPage; // See ppTypes
lDevice.Publisher := ppReport2.Publisher;
ppReport2.CachePages := True;
ppReport2.PrintToDevices;
LoadRawReportTable; // Function to extract Text & position from
TppDBText components by looping through all components on form.

Finally
lDevice.Free;
Screen.Cursor:=CRDefault;
End;

Comments

  • edited June 2004
    Hi Neil,

    It is possible to use a report object loop to access the report components
    in a subreport with recursion. Something like the following...

    procedure AssignFontToReport(aFont: TFont; aReport: TppCustomReport);
    var
    liBand: Integer;
    liObject: Integer;
    lObject: TppComponent;

    begin

    for liBand := 0 to aReport.BandCount-1 do

    for liObject := 0 to aReport.Bands[liBand].ObjectCount-1 do
    begin
    lObject := aReport.Bands[liBand].Objects[liObject];

    if (lObject is TppSubreport) then
    AssignFontToReport(aFont, TppSubreport(lObject).Report);

    if lObject.HasFont then
    lObject.Font := aFont;

    end;

    end;

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited June 2004
    Nico:

    I fail to see how your answer addresses my problem. I know how to find
    the subreport band. What I need to do is find the position and text rendered
    on that subreport band.

    I have identified the subreport band in my code - but the subreport
    itself does not own any components so I cant use it to recurse anything.

    Near as I can tell, I will need to recurse thru the draw commands.

    1) If the code below is relevent, can you explain how to use it ???

    2) If I need to get access to the draw commands, can you show me how to
    accomplish that ???

    Thank you.


    Neil Huhta






  • edited June 2004
    Hi Neil,

    Sorry, maybe I'm misunderstanding the issue.

    Draw commands are created on the fly as the report is generated, as well as
    page dimensions, component spacing and component position. Once the report
    generation process is done, the publisher will send each page to the defined
    device which will in turn loop through each draw command in the
    TppPage.DrawCommands list and render it to that device.

    Depending on when and how you are extracting the data from the report, you
    could create a custom device that receives a TppPage, then loops through
    each draw command gathering information and updating it as it goes (very
    similar to the TppTextFileDevice).

    If you would like to gain access to the actual draw commands as the report
    is generated, you will need to use the Component.OnDrawCommandCreate event
    for each component in your report. It would be possible to change each draw
    command here but you will then have to code a number of separate event
    handlers which could "clutter" your code.

    Sorry, the code I gave you below is not really relevant unless you are
    creating a static report where you can calculate the position of each
    component before the report is printed.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited June 2004
    Nico:

    My code is listed below:

    Screen.Cursor:=CrHourGlass;
    ppReport2.PassSetting:= psTwoPass;
    lDevice := TppDevice.Create(fmReport);
    lDevice.PageSetting := psLastPage;
    lDevice.Publisher := ppReport2.Publisher;
    ppReport2.CachePages := True;
    ppReport2.PrintToDevices;

    Once I call PrintToDevices, how do I create a custom device ??? Where do
    I get information on creating the custom device ???

    I am not using reportBuilder to print - I am simply using it to generate
    the Text in the Report Objects, then I will manually handle printing. This
    is done because I am doing Dot Matrix printing.

    Any help would be appreciated. Thank you.


    Neil Huhta
  • edited June 2004
    Hi Neil,

    Sorry for the delay in this response. I was thinking about your situation a
    little further and remembered that you have access to the
    Device.OnReceivePage event so you may not need to create a new device.
    Using the current printer device, you could tie into this event, extract
    each draw command from the TppPage object that is sent, alter them as you
    need, then send them to your printer manually (as you planned to do
    initially). This event will fire after you call PrintToDevices.

    --
    Thanks for supporting ReportBuilder! Please vote for ReportBuilder in the
    Delphi Informant Readers Choice awards!

    http://www.delphizine.com/ballot2004/

    Best Regards,

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