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

add report-event at runtime (DetailBand1BeforePrint)

edited April 2009 in End User
Hello Newsgroup..

using Delphi7 and RB9.01...

If i create a report with the "end-user-report-designer" and save this
report as rtm-file, i can use this rtm-file via
"ppreport1.Template.LoadFromFile" ...

But:
how can i execute code in the "DetailBand1BeforePrint-Event" without create
such event in designtime ?

Thanx for help.

regards

Erich


----------------------------------------------

i want to execute this code in any report:

uses ppClass;
...

procedure do_it;
var x:integer;
schleife_baender : Integer;
schleife_Objekte : Integer;
eine_Componente : TppComponent;
begin

for schleife_baender := 0 to ppReport1.BandCount-1 do
begin

for schleife_Objekte := 0 to
ppReport1.Bands[schleife_baender].ObjectCount-1 do
begin
eine_Componente :=
ppReport1.Bands[schleife_baender].Objects[schleife_Objekte];

if eine_Componente.ClassName = 'TppLabel' then
begin
if (eine_Componente as TppLabel).Caption = 'Wert1' then
(eine_Componente as TppLabel).Caption :='gefunden1';
if (eine_Componente as TppLabel).Caption = 'Wert2' then
(eine_Componente as TppLabel).Caption :='gefunden2';
if (eine_Componente as TppLabel).Caption = 'Wert3' then
(eine_Componente as TppLabel).Caption :='gefunden3';
end;


end;
end;

end;

Comments

  • edited April 2009
    Hi Erich,

    There are two options...

    1. Use RAP to code your event handlers so they stay local to the report.
    RAP is included with ReportBuilder Enterprise edition.

    http://www.digital-metaphors.com/products/rap/

    2. Use the Template event OnLoadEnd to assign the event handler to the
    detail band of the report once the report has loaded. See the following
    article on using Template events.

    http://www.digital-metaphors.com/rbWiki/Design/Templates/Using_Template_Events

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited April 2009
    OK.. the first Problem is solved..

    Next Problem ;-)

    On the report - i can just read the same Record (the first one in table) in
    "TForm1.my_BeforePrint"
    How can i read the current record, witch is used in the DetailBand

    thanX

    Erich




    // FirebirdSQL <-> ZConnection1 <-> ZQuery1 <-> DataSource1 <->
    ppDBPipeline1 <-> ppReport1






    create Event for beforePrint
    -------------------------------------------------------------
    procedure TForm1.SpeedButton1Click(Sender: TObject);
    var
    schleife_baender : Integer;
    schleife_Objekte : Integer;
    begin

    for schleife_baender := 0 to ppReport1.BandCount-1 do
    begin

    if ppReport1.Bands[schleife_baender].ClassName = 'TppDetailBand'
    then
    begin
    ppReport1.Bands[schleife_baender].BeforePrint:= my_BeforePrint;
    // !!!!!!!!!!!!!!!
    end;
    end;

    ppreport1.Print;
    end;
    -------------------------------------------------------------






    my own "beforeprint"
    --------------------------------------------------------------
    procedure TForm1.my_BeforePrint(Sender: TObject);
    var x:integer;
    schleife_baender : Integer;
    schleife_Objekte : Integer;
    eine_Componente : TppComponent;
    begin

    for schleife_baender := 0 to ppReport1.BandCount-1 do
    begin

    if ppReport1.Bands[schleife_baender].ClassName = 'TppDetailBand'
    then
    begin

    for schleife_Objekte := 0 to
    ppReport1.Bands[schleife_baender].ObjectCount-1 do
    begin
    eine_Componente :=
    ppReport1.Bands[schleife_baender].Objects[schleife_Objekte];

    if eine_Componente.ClassName = 'TppLabel' then
    begin
    // !!!!!!!!!!!!!!!!!!! Problem Start
    if (eine_Componente as TppLabel).Caption = 'Wert1' then
    (eine_Componente as TppLabel).Caption
    :='gefunden1:'+ZQuery1.FieldByName('OBJECT_NAME').AsString;
    if (eine_Componente as TppLabel).Caption = 'Wert2' then
    (eine_Componente as TppLabel).Caption
    :='gefunden2:'+VarToStr(DataSource1.DataSet.FieldValues['OBJECT_NAME']);
    if (eine_Componente as TppLabel).Caption = 'Wert3' then
    (eine_Componente as TppLabel).Caption
    :='gefunden3:'+VarToStr(ppDBPipeline1.FieldValues['OBJECT_NAME']);
    end;
    // !!!!!!!!!!!!!!!!!!!!! Problem End


    end;
    end;
    end;
    end;
    -------------------------------------------------------------------
  • edited April 2009
    Hi Erich,

    The report traverses through each record as the report is being generated.
    You will need to use an event such as the DetailBand.BeforePrint to access
    the current record being retrieved. An easy way to access a field value
    from the report is to use the DataPipeline property...

    lMyValue := ppReport1.DataPipeline['MyField'];

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