event handler in delphi

edited 12:34PM in FastReport 3.0
Hi, I'm trying to do the following but the event handler TForm1.OnBeforePrint is never called. What am i doing wrong ?
procedure TForm1.InitReport;
var
  Page : TfrxReportPage;
  Cross : TfrxCrossView;
begin
  // Create a new function
  frxReport1.AddFunction('procedure Cross1OnBeforePrint(Sender: TfrxComponent)', 'DelphiHandler');

  // Add the TfrxCrossView to it
  Page := TfrxReportPage(frxReport1.FindObject('Page1'));


  Cross := TfrxCrossView.Create(Page);

  Cross.Name := 'Cross1';
  Cross.SetBounds(0,0,20,15);
  Cross.RowLevels := 1;
  Cross.ColumnLevels := 1;
  Cross.OnBeforePrint := 'Cross1OnBeforePrint';
  Cross.OnAfterData := TfrxNotifyEvent

  FCross := Cross;
//  frxReport1.PrepareReport(true);
  frxReport1.DesignReport;
//  frxReport1.ShowReport;
end;

procedure TForm1.OnBeforePrint;
var
  Page : TfrxReportPage;
begin
  ShowMessage('Hello from delphi');
  FCross.AddValue(['Binnen 1 week'], ['Q1 2005'], [0.6]);

{
  Page := frxReport1.FindObject('Page1') as TfrxReportPage;
  Cross := Page.FindObject('Cross1');
}

end;

function TForm1.frxReport1UserFunction(const MethodName: String;
  var Params: Variant): Variant;
begin
  if MethodName = UpperCase('Cross1OnBeforePrint') then
    OnBeforePrint;
end;

Comments

  • edited March 2006
    Use frxReport.OnBeforePrint event:
    procedure TForm1.InitReport;
    var
     Page : TfrxReportPage;
     Cross : TfrxCrossView;
    begin
     // Add the TfrxCrossView to it
     Page := TfrxReportPage(frxReport1.FindObject('Page1'));
    
    
     Cross := TfrxCrossView.Create(Page);
    
     Cross.Name := 'Cross1';
     Cross.SetBounds(0,0,20,15);
     Cross.RowLevels := 1;
     Cross.ColumnLevels := 1;
     Cross.OnBeforePrint := 'Cross1OnBeforePrint';
     Cross.OnAfterData := TfrxNotifyEvent
    
     FCross := Cross;
    //  frxReport1.PrepareReport(true);
     frxReport1.DesignReport;
    //  frxReport1.ShowReport;
    end;
    
    procedure TForm1.frxReport1BeforePrint(Sender: TfrxReportComponent);
    var
     Page : TfrxReportPage;
    begin
    if (Sender is TfrxCrossView) and (Sender.Name = 'Cross1') then
    Begin
     ShowMessage('Hello from delphi');
     TfrxCrossView(Sender).AddValue(['Binnen 1 week'], ['Q1 2005'], [0.6]);
    end;
    end
    
  • edited 12:34PM
    I have tried the code but don't work.

    I don't know well delphi to undestand the problem, and for this reason i need help.

    Be patient for my very stupid question:

    Why this row i not closed with ;
    Cross.OnAfterData := TfrxNotifyEvent

    What is FCross and where is declared?
    FCross := Cross;

    The event procedure TForm1.frxReport1BeforePrint give me compile error.

    Thank you.

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.