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

RAP fonction dynamicaly

edited September 2004 in End User
Hi,

I'm using RB 7.04 with Delphi 6

In my code I write this fonction

procedure DefineRAPCode(aReport : TppReport);
var
lCodeModule : TraCodeModule;
lNewEventHandler : TraProgram;
ComponentEvent : TppCommunicator;
i : integer;
begin
ComponentEvent := nil;
{Search TppImage Component}
for i := 0 to aReport.Detail.ObjectCount-1 do
begin
if (AnsiCompareText(aReport.Detail.Objects[i].ClassName,'TppImage')
= 0)
and
(AnsiCompareText(TppImage(aReport.Detail.Objects[i]).UserName,'photo') = 0)
then
ComponentEvent := aReport.Detail.Objects[i];
end;
{get the module for report}
lCodeModule := raGetCodeModule(aReport);
if lCodeModule = nil then
begin
lCodeModule := TraCodeModule.Create(aReport);
lCodeModule.Report := aReport;
end;
{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}
if assigned(ComponentEvent) then
begin
lNewEventHandler :=
lCodeModule.CreateEventHandler(ComponentEvent,'OnPrint');
{Set BodyText to modify the code beetwenn the begin end}
lNewEventHandler.BodyText := 'LoadFromFile(badge[''Chemin du fichier
photo''],photo.Picture);';
{compile the code}
lCodeModule.BuildAll(TRUE);
end;
end;

So, when I delete the TppImage Component. I'am an error.





Why? Is it possible to correct this problem?


Thanks
Wilfried Deguil

Comments

  • edited September 2004

    The CodeModule should have the same owner as the report, that might be
    causing the problem. Try this:


    TraCodeModule.Create(aReport.Owner);


    --


    Best regards,

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