how to set a default for a script variable?

I often have a memo containing a script variable to show the year the report is about eg [thefeeyear] whose value I pass in at run time.

How can I set a default value so that I can check the preview of the form during design time (ie without compiling and running the whole program without it generating an error like this?


Comments

  • LurkingKiwiLurkingKiwi Wellington, New Zealand

    I'm not sure if this is supported in FR4, but in FR5 and 6 you can create Report Variables in the Designer and assign them a value, which you can override in code before using the report. They may not behave quite the same way, but its what I use.

  • Thank you. Please can you tell me how you do that so I can look in the right place in FR4. I don't think I've ever seen that feature but I might not be looking in the right place.

  • Ah! Found it, It's under the report|variables menu option. I didn't realise you could create a new variable there and give it a value at the same time. Thanks for your help, it saves a lot of time when developing

  • LurkingKiwiLurkingKiwi Wellington, New Zealand

    Just remember that report variables are more like macros, they are evaluated as expressions so you have to put quotes IN the variable value for strings. See the Programmers Manual Chapter 2.

  • LurkingKiwiLurkingKiwi Wellington, New Zealand
    edited February 2020

    I have found that if a FastReport variable's new value has a CRLF in it, then the outer quotes get printed, otherwise they are required to stop FR doing a recursive variable lookup.

    I have a function like this:

    procedure SetReportVar(Report : TfrxReport; TheVar, TheValue : string);
    begin
    if pos(#13, TheValue) > 0 then {Assume correct CRLF pairs used in string so use directly}
      Report.Variables[TheVar] := TheValue
    else {Need to surround with extra quotes to prevent recursive lookup}
      Report.Variables[TheVar] := '''' + TheValue + '''';
    end;
    


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.