How To…Implement Event-Handlers for Report Templates

Question

“How do I implement event-handlers for report templates?”

Solution

  1. The best solution is to code the calculations and event-handlers in RAP, the run-time Pascal coding evironment included with ReportBuilder Enterprise. RAP enables the event-handler code to be saved in the .rtm templates as part of the report definition.
  2. If you use Delphi event-handlers as you are doing now, all of the event-handler code must reside in the form upon which the TppReport component resides. As you have discovered, you must write the code in such a manner as to not refer to any components directly by name.
procedure TForm1.ppLabel1Print(Sender: TObject);
var
  lComponent: TComponent;
  lLabel: TppLabel;
begin

  lComponent := FindComponent('Label1');

  if (lComponent is TppLabel) then
    begin
      lLabel := TppLabel(lComponent);
      lLabel.Caption := 'Hello Caption';

    end;

end;