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

Images and labels not changing when using Templates

edited July 2004 in General
Hi! I'm using the LoadfromFile procedure to assign a Template to a
report. In the template I have a label and a image that change dinamically
as I
print the report (the label is for diferent copys description : 'File',
'Copy1' etc)
and the image is for a BarCode image. So I use the before print event and
assign label.caption := 'xxx' and image.picture.loadfromfile('filename');

I debug the code and the event is being called and the code is being done
but something isn't working because when I see the report: there is no
diference on the label and the image!!

I have also a variable on the templete and write code on the oncalc event,
and the code here works fine, I can see the results on the report, so
I change the code on label.onprint for a variable.oncalc (as string) and
it's works that way but I dont have any idea on how to make it happen for
the image.

Why is this happening? The events and the code just seem to work fine.
Also if a print the report directly without make the LoadfromFile the code
works , but
I just need to make it from the Loadfromfile way.

Comments

  • edited July 2004
    Hi Eugenio,

    When loading templates, there is always a possibility of loosing event
    handlers. Please see the article below on troubleshooting lost event
    handlers when using Report Templates.

    --------------------------------------------
    Article: Troubleshooting Lost Event Handlers
    --------------------------------------------

    Let's assume you have created a report in Delphi and assign an event
    handlers to the OnPreviewFormCreate event of the report. The event is
    generated by Delphi as:

    procedure TForm1.ppReport1PreviewFormCreate(Sender: TObject);

    You then save the report to an RTM file 'Report1.RTM.' The events are
    stored as references only, and so the RTM contains:

    object ppReport1: TppReport
    .
    .
    OnPreviewFormCreate = ppReport1PreviewFormCreate
    end

    You then go on to work on a different report. Saving it with under then
    name 'Report2.RTM'. Only this time, before you save the report you
    change the report component name to: rptOrders. Delphi automatically
    updates the event declaration for OnPreviewFormCreate event to:

    procedure TForm1.rptOrdersPreviewFormCreate(Sender: TObject);


    You then create two buttons on the form, one to load Report1 and
    preview, the other to load Report2 and preview. When you run the app
    and click Report1, you an error. This is because the Report1.RTM file
    contains a reference to ppReport1PreviewFormCreate, a method which no
    longer exists (at least with this name) in the form.

    One answer is to load all your rtm files into the report component you
    will be using for loading. Fix any errors, reassign any events that get
    cleared. This will update your rtms to contain the proper event handler
    names.


    --
    Best Regards,

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