Content of variable raises an exception - Expression expected

edited 3:32AM in FastReport 4.0
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.

Comments

  • Anu de DeusAnu de Deus Hampshire, UK
    edited 3:32AM
    DateRange.AllowExpressions := true / false
  • edited 3:32AM
    DateRange.AllowExpressions := true / false

    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.
  • Anu de DeusAnu de Deus Hampshire, UK
    edited 3:32AM
    In that case, try changing the format string to text only
  • gordkgordk St.Catherines On. Canada.
    edited 3:32AM
    make sure you pass the string value into the variabole correctly
    you need extra delimiters.
  • edited 3:32AM
    gordk wrote: »
    make sure you pass the string value into the variabole correctly
    you need extra delimiters.

    Do you mean?

    Variables := QuotedStr (somevar);
  • gordkgordk St.Catherines On. Canada.
    edited 3:32AM
    the value must end up in the report as
    'somestringtrxt' note the extra delimiters.
    not
    like this
    somestringtext

    read the programmers manual on working with variables
  • edited 3:32AM
    Try this - OnBeforePrint event for your Memo:
    procedure Memo1OnBeforePrint(Sender: TfrxComponent);
    begin
      Memo1.Text := Report.Variables['DateRange'];                                       
    end;
    

    Mick
  • gordkgordk St.Catherines On. Canada.
    edited 3:32AM
    Mick that just stops the variable from being used until it is added to the memo
    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' + '''';

  • edited 3:32AM
    Yes GordK, you are right - manipulating string variables need quoted strings.

    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:
    var 
       s :string;
    
    procedure Memo2OnBeforePrint(Sender: TfrxComponent);
    begin
      Memo2.Text := Report.Variables['MyVar'];                                     
    end;
    
    begin
       s := '(1.3.2011 - 31.3.2011)';
       Report.Variables['MyVar'] := s;                                                                                                                  
    end.
    

    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
  • edited 3:32AM
    gordk wrote: »
    because FastReport trying to calculate a value of such variable. The right way to pass a string values is:



    frxReport1.Variables := '''' + 'test' + '''';

    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.
  • edited 3:32AM
    Why do you need a QuotedStr? I made it this way:
    var s  :string;
      
    procedure Memo2OnBeforePrint(Sender: TfrxComponent);
    begin
      s  := 'Actual month ' + ' (1.3.2011 - 31.3.2011)';
      Report.Variables['My Variable'] := s;
    end;
    
    See attached examples.

    Mick
  • edited 3:32AM
    Mick.pl wrote: »
    Why do you need a QuotedStr? I made it this way:
    var s  :string;
      
    procedure Memo2OnBeforePrint(Sender: TfrxComponent);
    begin
      s  := 'Actual month ' + ' (1.3.2011 - 31.3.2011)';
      Report.Variables['My Variable'] := s;
    end;
    
    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.
    >
  • edited 3:32AM
    Mick.pl wrote: »
    Why do you need a QuotedStr? I made it this way:
    var s  :string;
      
    procedure Memo2OnBeforePrint(Sender: TfrxComponent);
    begin
      s  := 'Actual month ' + ' (1.3.2011 - 31.3.2011)';
      Report.Variables['My Variable'] := s;
    end;
    
    See attached examples.

    Mick

    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;
  • gpigpi
    edited 3:32AM
    This code works OK for me:
    var s: string;
    begin
         s:= QuotedStr('Actual month ' + ' (1.3.2011 - 31.3.2011)');
         frxReport1.Variables['My Variable'] := s;
         frxReport1.ShowReport();
    end;
    
    wrote:
    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;
    Use script variables. See Programmer's manual
    wrote:
    It should be noted, that when accessing a report variable its value is calculated if it
    is of string type. That means the variable which value is 'Table1."Field1"' will return a
    value of a DB field, but not the 'Table1."Field1"' string. 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.
  • edited 3:32AM
    wrote:
    Inside of report the view contains:

    DateRange.Memo.Text := '[DateRange]';
    Have a look at my example fr3 and contents of Memo3:

    [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
  • gpigpi
    edited 3:32AM
    wrote:
    ext, 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.
    Or use script variable

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.