简体   繁体   中英

How to write events of “fastreport band” in delphi code

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;

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;

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM