Is it possible to display Delphi variables in a report?
I love FastReport - so much better than the reports in Access. However..
In my delphi code I use functions to generate dates that are then used as criteria in the initial query that feeds my report.
I've also stored them as strings in the same form/unit that contains the FastReport and have made functions to return these strings and declared them in the public part of the form definition containing the report. (Hope that makes sense!)
I'd like to display these strings on the report as headers, above the appropriate column, to show the criteria that was used.
I've played arpound with the using a text object to try to display the result of my delphi function using things like [Form2.getFirstDate] but get an undefined variable error all the time.
Can we use delphi variables or the result of delphi functions in our reports?
If so, how?
Howard
In my delphi code I use functions to generate dates that are then used as criteria in the initial query that feeds my report.
I've also stored them as strings in the same form/unit that contains the FastReport and have made functions to return these strings and declared them in the public part of the form definition containing the report. (Hope that makes sense!)
I'd like to display these strings on the report as headers, above the appropriate column, to show the criteria that was used.
I've played arpound with the using a text object to try to display the result of my delphi function using things like [Form2.getFirstDate] but get an undefined variable error all the time.
Can we use delphi variables or the result of delphi functions in our reports?
If so, how?
Howard
Comments
Read the programmers manual on working with categorized variables, and the ongetvalue event as well. you can set the values of categorized variables after a report is loaded and before calling
show or prepare it can also be set from the obp event of the tfrxreport component.
Hint when passing string values in to a categorized variable you must use extra string delimiters.
or the variable when used, will appear to be an unknown expression an it will cause an error to be
thrown unless a handler has been written for the ogv event
Thank you
I have defined my variables under a new category and can see them in the tree, (one of them is called DateOfWeekMinus6)
My tfrxreport component is called frxReportLeagueTable, it is on Form2. This form also contains in the interface a global variable called strDateLastWeekMinus6.
I have put the following in the frxReportLeagueTableOnReportPrint event but I get an 'unknown identifer' error on frxReportLeagueTable (the report name).
I also tried putting the same line in the BeforePrint event of a text object (Memo12OnBeforePrint) and also dragged the variable from the tree onto my report and put the same line in its BeforePrint event (DateOfWeekMinus6OnBeforePrint) each time getting an unknown identifer on frxReportLeagueTable.
Any ideas?
Howard
Put this before any call to Show or Prepare:
frxReport1.OnUserFunction := CustomReportFunction;
frxReport1.AddFunction('function SetDocImgRef(const s: string) :string;', 'MyFuncs'); << this is your function, declare it the way you would in a .pas unit, plus the group name (not relevant unless in the report designer)
function TYourForm.CustomReportFunction(const MethodName: string; var Params: Variant): Variant;
var
lStr1: string;
begin
result := MethodName;
if MethodName = 'SETDOCIMGREF' then << YOU MUST HAVE IT UPPERCASE IN THE COMPARISON HERE, or use CompareText() instead
result := SetNewDocImgRef(Params[0]) << this is your function being called
else
(...)
end;
And this is your function:
function TYourForm.SetNewDocImgRef(const s: string): string;
begin
result := 'Easy example '+s;
end;
TYourForm is your form or class where you are doing everything from, where you have your frxReport1 object.
After that you can call the function SETDOCIMGREF from the frx Script or put in a memoview as the text property, like '[SETDOCIMGREF('test')]'
If you didn't understand, search for OnUserFunction and AddFunction in the manuals
Thank you I shall have a go (although it still does noes not explain whey I get an unknown unidentifier error by simply substituting into the manual's code the real name of my report instead of frxReport1) .
Which manuals are you referring to? I've searched both the User Manual and the Programmers manual and neither of them have any reference to OnUserFunction - or any function come to that.
Howard