Home DADE

OnPreviewFormCreate Error loading SQL

edited June 2004 in DADE
Hi All,

While loading an .rtm using template.loadfromfile, I get an error message
'Error reading ppReport.OnPreviewFormCreate. Invalid property value' Here is
my code.

procedure TForm1.btnShowSQLClick(Sender: TObject);
var
iSQL : TdaSQL;

begin
Memo.Lines.Clear;

if FileExists(edtReportPath.FileName) then begin
TempReport := TppReport.Create(self);
TempReport.OnPreviewFormCreate := nil;

try
with TempReport do begin
{Template.OnLoadStart := myTemplateOnLoadStartEvent;}
// Get SQL OnLoadEnd
Template.OnLoadEnd := myTemplateOnLoadEndEvent;
Template.Filename := edtReportPath.FileName;
Template.LoadFromFile; {Error Occurs Here !!!}
end;
finally
FreeAndNil(TempReport);
end;
end;
end;

How do I get rid of this error message?

Thanks,
Stacey

Comments

  • edited June 2004

    This error indicates that the .rtm file contains a reference to an
    OnPreviewFormCreate event-handler that cannot be found when the report is
    loaded. For details see the article below.

    One solution is to use RAP event-handlers, that way the event-handler code
    is saved to the .rtm.

    Another solution is to make the event-handlers published methods of the
    form/datamodule that owns the TppReport.





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


    --
    Tech Support mailto:support@digital-metaphors.com
    Digital Metaphors http://www.digital-metaphors.com

    --

    Nard Moseley
    Digital Metaphors Corporation
    www.digital-metaphors.com



    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
This discussion has been closed.