Home Subreports

Problem with creating event-handler in runtime

edited December 2004 in Subreports
Hi, I have a problem :

I'm generating EventHandler in run-time for TppVariables components. The
problem is that when these TppVariables are in sub-reports,
CreateEventHandler call fails. Why? Here's my code:

procedure TFormMain.CreateVariableFormula(_ppVariable: TppVariable;
_strFormula: string);
var
lEventHandler: TraEventHandler;
AppReport: TppCustomReport;
lCodeModule : TraCodeModule;
begin

{get the codemodule for the report}
AppReport := _ppVariable.Report;
lCodeModule := raGetCodeModule(AppReport);

{CreateEventHandler: parameters: Component, EventName
- calling this method will create a RAP event-handler and
generate a program shell containing the program declaration plus begin
end}

lEventHandler := lCodeModule.CreateEventHandler(_ppVariable, 'OnCalc');

{set BodyText to modify the code between the begin..end}
lEventHandler.BodyText := ConvertFormula(_strFormula); // Call formula
text conversion

{compile the code without exception on error}
lCodeModule.BuildAll(False);

end;

Thank you!

Comments

  • edited December 2004
    I found the problem :

    in a sub-report, if I call

    lCodeModule := raGetCodeModule(AppReport);

    with AppReport as TppChildReport, lCodeModule returns nil. Is this an issue
    in RB ?

    David Caouette

    "David Caouette" a ?crit dans le message de
  • edited December 2004
    I still have the problem:

    between the two following lines:

    AppReport := _ppVariable.Report;
    lCodeModule := raGetCodeModule(AppReport);

    I put the following piece of code:

    if (AppReport is TppChildReport) then
    begin
    repeat
    AppReport := AppReport.MainReport;
    until (AppReport.MainReport = AppReport);
    end;

    Then, raGetCodeModule(AppReport) returns something. But the call to
    CreateEventHandler still fails. Why?

    David Caouette

    "David Caouette" a ?crit dans le message de
  • edited December 2004

    Each report and childreport can have 0 or 1 CodeModules. In other words a
    CodeModule is created as needed.

    Try something like this:

    lCodeModule := raGetCodeModule(myVariable.Report);

    // create if needed
    if (lCodeModule = nil) then
    lCodeModuel := TraCodeModule.CreateForReport(myVariable.Report);






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



    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited December 2004
    Thank you! It was my mistake :-s.

    David Caouette

    P.S: ReportBuilder is now our new standard for reporting. We're now
    migrating every Crystal Report to ReportBuilder and conversion is going
    pretty well. Our support for the reports won't be a pain anymore. Thanks
    again, Digital Metaphors!

This discussion has been closed.