Content of variable raises an exception - Expression expected
Hello all,
I have code:
s := '(1.3.2011 - 31.3.2011)';
frxReport.Variables := s;
Inside of report the view contains:
DateRange.Memo.Text := '[DateRange]';
but when I want to print out this view, then an exception is raised "Expression expected". I know that it detects two dates and minus between them as something to be parsed, but it is just an stupid text to be printed out.
How can I deliver any text over variables without being parsed when I don't want to parse it?
Thanks for all suggestions.
Fred.
I have code:
s := '(1.3.2011 - 31.3.2011)';
frxReport.Variables := s;
Inside of report the view contains:
DateRange.Memo.Text := '[DateRange]';
but when I want to print out this view, then an exception is raised "Expression expected". I know that it detects two dates and minus between them as something to be parsed, but it is just an stupid text to be printed out.
How can I deliver any text over variables without being parsed when I don't want to parse it?
Thanks for all suggestions.
Fred.
Comments
Thanks for fast answer, but this I have already tried before I wrote into forum and doesn't help. When I deny expressions the print out contains the content of Memo.Text which will be simply "[DateRange]".
I need to print out the content of variable, but without any execution of its content.
you need extra delimiters.
Do you mean?
Variables := QuotedStr (somevar);
'somestringtrxt' note the extra delimiters.
not
like this
somestringtext
read the programmers manual on working with variables
Mick
the variable must be correct or it will still create the error.
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' + '''';
But as Fred said he wanted just to print a simple text, so I followed his idea. I mean I didn't see any his wish to make a use of this variable in any other purpose than to add it to the memo.
I wrote code like below:
And the above code works without generating any erros - as I do not make any calculations with Report.Variables.
Yet I think, that FR variables aren't necessary at all if one wants to add a simple text to the memo.
In such case I would do:
var s :string
begin
s := '(1.3.2011 - 31.3.2011)';
end
and at design time I would fill the memo with:
Mick
Thanks GordK for answer, but I know many years I need to close string into quotes to work it out as text, but try please this:
s:= QuoteStr ('Actual month ' + ' (1.3.2011 - 31.3.2011)');
frxReport1.Variables := s;
you will see, that FR want to evaluate instead of using it as simple text.
See attached examples.
Mick
I see you moved a part of code into fr3 file. But I don't want to have any report logics inside of fr3 file, because users are used to create own report files and when report file would need to program some parts they will not be able to do that. My report file must be only simple report file without any code. Memo gets raw data from data field or from variable.
That's all.
The biggest problem is/was that I have this on some places this expression:
s := 'Actual month' + #13+#10 + '(1.3.2011 - 31.3.2011)';
Report.Variables := s;
[Report.Variables]
So try to change your code into:
DateRange.Memo.Text := '[Report.Variables]'
Next, as Gpi suggests - you can't use #13#10 inside the string. Try to put two memos one above the other and put necessary texts in each of them - this will allow you to avoid using of #13#10.
Mick