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

Modifying a report at run time

edited August 2007 in General
I need to add labels etc (within a region) to a report at run time,
where the report has been created using the IDE. Is this possible? If
so, where do I put the code? Or do I have to start again and create the
whole report in code?
Thanks in advance
Glen

Glen

--- posted by geoForum on http://delphi.newswhat.com

Comments

  • edited August 2007
    Hi Glen,

    The best place to modify or add components to a report at runtime is inside
    an event that fires before the report prints. The BeforePrint event is a
    good choice for instance.

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited August 2007
    Nico,
    Thanks for this answer. It is fairly obvious, given I was already using
    BeforePrint for simple value calculations etc. I thought there would be
    an earlier event for more structural things affecting the report layout.

    Another couple of questions.
    1.When I create labels etc I have to set owner to nil as Sender isn't
    used (as explained in doco). Will I have to free them explicitly?
    2.I am having trouble assigning a band to a component e.g. a TppLabel:
    MyLabel1.Band := HeaderBand;
    MyLabel1.Band := MyReport.HeaderBand;
    both fail. Do I need to set a global variable to MyReport, or something
    like that?
    TIA,
    Glen

    inside an event that fires before the report prints. The BeforePrint
    event is a good choice for instance.

    Glen

    --- posted by geoForum on http://delphi.newswhat.com
  • edited August 2007
    Hi Glen,


    What exactly are you trying to accomplish? There are numerous events that
    fire before the BeforePrint event however they were primarily added to allow
    the alteration of data before the report generates. The best place to
    add/remove components from a report is still the BeforePrint event.

    Are you using RAP? When creating report components, you should set the
    owner to the main form (Self) giving it the responsibility of freeing that
    component when the app closes. Take a look at the CodeBased thread in the
    Tech-Tips newsgroup for some examples of creating reports completely in
    code.


    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited August 2007
    >What exactly are you trying to accomplish?

    I have a report created in the IDE. Now I have to add a region (that will
    run to several pages per database record) in a way that omits data
    (including its identifying labels) if it is missing (blank/zero/false
    etc). It seemed to me i would have to do this in code. Maybe there is a
    better way?

    I would like to avoid re-creating the whole existing report in code, if
    possible. Is the answer that I can't create additional components in
    code in a report that was created in the IDE?

    ...
    ...
    Yes, I am using RAP, but in the BeforePrint event of a report created in
    the IDE, Self is not recognized, and the report name is not recognized.
    Glen

    Glen

    --- posted by geoForum on http://delphi.newswhat.com
  • edited August 2007
    Hi Glen,

    For future reference, please let us know that you are using RAP (or post in
    the RAP newsgroup) when asking a question pertaining to it. This helps us
    understand which features of RB you are using and allow us to answer your
    questions easier and more promptly.

    When creating components in RAP, you can give it the Report.Owner which is
    essentially the form. Use the object names in the report objects window in
    the code editor rather than the names you would use in Delphi.

    var
    lLabel: TppLabel;
    begin

    lLabel := TppLabel.Create(Report.Owner);
    lLabel.Band := Detail;
    lLabel.Caption := 'hi';

    lLabel.Font.Name := 'New Times Roman';
    lLabel.Font.Size := 24;

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