Passing a variable value in TfrxReport.OnGetValue

Top  Previous  Next

The last way to pass a value to a report is to use the “TfrxReport.OnGetValue” event handler. This is convenient when a dynamic value is to be passed to a report (a value that may change from record to record). The two previous ways are suitable for passing static values.

 

Let's look at an example of using this event handler. Create a report and place a "Text" object in it. Type the following text into this object:

 

[My Variable]

 

Now create the “TfrxReport.OnGetValue” event handler:

 

procedure TForm1.frxReport1GetValue(const VarName: String;

                                   var Value: Variant);

begin

 if CompareText(VarName, 'My Variable') = 0 then

   Value := 'test'

end;

 

Run the report and see that the variable is displayed correctly. The “TfrxReport.OnGetValue” event handler is called each time that FastReport finds an unknown variable. The event handler should return a value for that variable.