How to pass constant values to frxReport?
How can I pass constant values to a report?
I want to pass more info than provided by the ReportOptions: Author, Name etc.
I have this need, because I store report forms in the database to allow users to build their own reports. The extra information is fixed for the report upon starting, but variable for the application itself.
I have tried report.variables := 'xx'; This won't work.
Please help me out.
I want to pass more info than provided by the ReportOptions: Author, Name etc.
I have this need, because I store report forms in the database to allow users to build their own reports. The extra information is fixed for the report upon starting, but variable for the application itself.
I have tried report.variables := 'xx'; This won't work.
Please help me out.
Comments
This is from the Programmer's Manual:
<span style='color:blue'>
You should be careful when assigning a string-type values to report variables. For example, the next code will raise exception "unknown variable 'test'" when running a report:
frxReport1.Variables := 'test';
because FastReport trying to calculate a value of such variable. The right way to pass a string values is:
frxReport1.Variables := '''' + 'test' + '''';
In this case the variable value - string 'test' will be shown without errors. But keep in mind that:
- string should not contain single quotes. All single quotes must be doubled;
- string should not contain #13#10 symbols.
In some cases it is easier to pass variables using a script.
</span>
Link to the On-line documentation
try this
on the "GetValue" event of 'frxReport'
procedure TFrmGeneral.frxReportGetValue(const VarName: String;
var Value: Variant);
begin
if (VarName = 'Report_Variable_Name') then
Value := 'Nemesis';
end;
Report_Variable_Name := This a variable created in your report.
Nemesis := Value assigned to variable (in your case constant value)
good look