How to write events of "fastreport band" in delphi code

6.2k views Asked by At

I have masterdata band in my fastreport. I can write code on "masterdata After print" in pascal script, but i want to know is there a way to write this code in main delphi form.

Pascal script:

procedure MasterDataOnAfterPrint(Sender : TfrxComponent) 
begin
   Sup_Page.Text := 'Cont on Page ' + IntToStr(<Page> + 1);
end;
1

There are 1 answers

1
bummi On BEST ANSWER

You have different options to interfer your report while printing.
You might use the events AfterPrint and/or BeforePrint which will provide the component as parameter for every time it will be printed.
If you want to access another component then the one which is provided in the events, you can use FindComponent delivering the component for the page actually printed.
To access functions within the report you can call Calc with the functions name as parameter .
An other option depending on your demands is to use the GetValue event which, will be called every time a variable is evaluated, providing the name of the variable and a var parameter for the value, which will enable you to return the value you like.
A short example might be useful:

procedure TFormOrDM.frxReport1AfterPrint(Sender: TfrxReportComponent);
begin
  // if Sender is TfrxMasterdata then  // Filter out all Masterdatasets
  if Sender.Name = 'Masterdata1' then // Filter out a specific Masterdatasets
  begin
    TFrxMemoView(frxReport1.FindComponent('Sup_Page')).Text := 'Cont on Page ' + FloatToStr(frxReport1.Calc('<Page>') + 1);
  end;
end;

procedure TFormOrDM.frxReport1BeforePrint(Sender: TfrxReportComponent);
begin
  // Another place you might use to acsess components
end;

procedure TFormOrDM.frxReport1GetValue(const VarName: string; var Value: Variant);
begin
  if VarName = 'myValue' then // own variable defined in the report
    Value := 'Cont on Page ' + FloatToStr(frxReport1.Calc('<Page>') + 1);
end;

enter image description here