Problem with creating event-handler in runtime
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!
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!
This discussion has been closed.
Comments
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
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
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
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!