问题
I am using Delphi 5 and Fast Report 4 to make a report application. I have defined a variable "ReportTitle" in MyReport.f3 at design time and I assigned a value for it at runtime. Why is my code raising an EStackOverflow Exception?
Here is the code sample
frxrprt1.LoadFromFile('c:\MyReport.fr3');
frxrprt1.Variables['ReportTitle'] := 'Sales Summary Report';
frxrprt1.ShowReport;
回答1:
Use this:
frxrprt1.Variables['ReportTitle'] := '''Sales Summary Report''';
The "variable" values are actually treated as full-fledged expressions; If you want it to be a string, it needs to be a standard pascal constant, using single-tick quoting; And since you're doing that from pascal code, you need to quote the quotes by double-quoting.
You probably get the stack overflow because fast report's scripting engine is trying to make sense of whatever you wrote and runs into a recursive problem.
回答2:
Or you can use another way.
frxrprt1.Variables['ReportTitle'] := QuotedStr('Sales Summary Report');
The function QuotedStr returns the string S, quoted with single quotes. This means that S is enclosed in single quotes, and every single quote in S is doubled. It is equivalent to a call to AnsiQuotedStr(s, '''').
来源:https://stackoverflow.com/questions/5963036/why-is-fast-report-vcl-in-delphi-raising-a-stack-overflow-exception-when-editing