Can't rename the TppReport control
Delphi 7, Report Builder version 10.06
With an empty project I drop a TppReport control onto a form. Under the
"Uses" section I add the following items so that my project will compile and
run:
ppComm, ppRelatv, ppProd, ppClass, ppReport, ppDB, ppDBPipe, ppPrnabl,
ppCtrls, ppBands, ppCache,
daDataModule, daDataView, daQueryDataView, daDBBDE, daSQLBuilder, daSQL;
As a test the OnFormCreate function loads a report and displays it with the
following code:
ppReport1.Template.FileName := 'c:\winjan\data\UserAcc.RTM' ;
ppReport1.Template.LoadFromFile ;
ppReport1.Print ;
When I run the program I get an error that says "Error reading
ppReport2.OnPreviewFormCreate: Invalid property value"
I can't see where its getting the name "ppReport2" from as the control I
added is "ppReport1".
So I added an OnPreviewFormCreate handler and everything worked fine. I then
renamed the TppReport control to m_ReportCtrl. This time when I run the
program I get an error that says "Error reading
ppReport1.OnPreviewFormCreate: Invalid property value". Note that this error
refers to "ppReport1" which doesn't exist !
When I ok the error message I then get a message box with three buttons but
only the middle button has any text on it. It says "Cancel". If I click on
the mystery right button my report is then shown !
I hope someone can reproduce this error or even better, tell me what I'm
doing wrong.
Ian Munro
With an empty project I drop a TppReport control onto a form. Under the
"Uses" section I add the following items so that my project will compile and
run:
ppComm, ppRelatv, ppProd, ppClass, ppReport, ppDB, ppDBPipe, ppPrnabl,
ppCtrls, ppBands, ppCache,
daDataModule, daDataView, daQueryDataView, daDBBDE, daSQLBuilder, daSQL;
As a test the OnFormCreate function loads a report and displays it with the
following code:
ppReport1.Template.FileName := 'c:\winjan\data\UserAcc.RTM' ;
ppReport1.Template.LoadFromFile ;
ppReport1.Print ;
When I run the program I get an error that says "Error reading
ppReport2.OnPreviewFormCreate: Invalid property value"
I can't see where its getting the name "ppReport2" from as the control I
added is "ppReport1".
So I added an OnPreviewFormCreate handler and everything worked fine. I then
renamed the TppReport control to m_ReportCtrl. This time when I run the
program I get an error that says "Error reading
ppReport1.OnPreviewFormCreate: Invalid property value". Note that this error
refers to "ppReport1" which doesn't exist !
When I ok the error message I then get a message box with three buttons but
only the middle button has any text on it. It says "Cancel". If I click on
the mystery right button my report is then shown !
I hope someone can reproduce this error or even better, tell me what I'm
doing wrong.
Ian Munro
This discussion has been closed.
Comments
The reason you are receiving an error is that the template is saving the
event name and location when you save it to file. Then when you load the
template, it is looking for that event and cannot find it. One solution is
to define all your events in RAP code keeping them local to the template.
Another is to assign all your events after the template has loaded using the
OnLoadEnd event perhaps.
--------------------------------------------
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.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
were causing me problems. I am now using your suggestions to rectify my
problem. Thank you.