How to add an event to MasterDetail?

edited November 2013 in FastReport 4.0
I am trying to print a series of labels. That is no problem. But sometimes I need to print a few blank labels. I can add code inside the report to the MasterData OnPrint event that will do the job. I simply look at a field in my dataset, and if false I make all the memo fields in the MasterData band invisible. The problem is, I have so many reports that I cannot go to each report and add the event manually. I need to do it in Delphi.

I have been trying to 'find' the MasterData component on the report, then to somehow assign an event. something like this

.....
         fMasterDataOnBeforePrint:TfrxNotifyEvent;
...... 
     procedure DoMasterDataOnBeforePrint(Sender: TObject);
      procedure SetReportMasterDataEvent(Report: TfrxReport; stName: string);
      property MasterDataOnBeforePrint: TfrxNotifyEvent read fMasterDataOnBeforePrint write fMasterDataOnBeforePrint;
   end;


procedure TPrintReport.SetReportMasterDataEvent(Report: TfrxReport; stName: string);
var
   db: TfrxMasterData;
begin
   DB := Report.FindObject(stName) as TfrxMasterData;
   if DB <> nil then
      begin
        db.OnBeforePrint :=DoMasterDataOnBeforePrint;
      end;
end; //
This suffers from two problems. First, I have to know the name of the MasterData component. This is usually fixed ('MasterData1'), so it is not a real problem, just not neat.

The main problem is that I cannot add the event. I understand that FR events are not like Delphi events - but I cannot seem to work out how to do it.

Any help in this regard will be most welcome.

Comments

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.