Checking Variables by the Report-Code on Preview

I like to create a report, using a variable which is set by a Delphi XE3 application.
But the report has although to run without getting the variable using a default value.

The report has to check itself, if the variable exists. If not , the report should work with
default values, so the preview can run without sent variables.

But the frxDesignerForm generate an error, when I dont send the variable by Delphi
code: ???unknown variable or datafield???.

In the script I can???t catch this error by try-except. The preview stops without using the default.

If I declare the variable in the report explicit (via menu item Report ??? Variables, add category,
add variable ???TPNR???) the Preview generate the error:
???Could not convert variant of type (Null) into type (OleStr)???

Is there a way to figure out, if the variable is declared and defined?

Delphi:
<!--fonto:Courier New--><span style="font-family:Courier New"><!--/fonto-->...
freport1.Script.Variables[???TPNR???] := ???123???;
...
<!--fontc--></span><!--/fontc-->
Report:
<!--fonto:Courier New--><span style="font-family:Courier New"><!--/fonto-->Begin
TRY
ADOTable1.filter := 'NR='+<TPNR>;
EXCEPT
ADOTable1.filter := 'NR=224';
END;
<!--fontc--></span><!--/fontc-->

Comments

  • edited 5:25PM
    My workaround:
    Before previewing/printing our Preview-application scans the fr3-file for variable-names
    (strings between '<' and '>' and assigns empty values to the vars

    Then the report-code works with try-except..

    Delphi-Preview application
    <!--fonto:Courier New--><span style="font-family:Courier New"><!--/fonto-->
    ...
    if (VarsInFastReport(RepName, list)>0) then begin
    for i := 0 to list.Count-1 do
    freport1.Script.Variables[list] := '';
    end;
    ...
    <!--fontc--></span><!--/fontc-->

    Report-code
    <!--fonto:Courier New--><span style="font-family:Courier New"><!--/fonto-->TRY
    ADOTblVoreingabe.filter := 'NR='+<TPNR>;
    EXCEPT
    ADOTblVoreingabe.filter := 'NR=224';
    END;
    // Filter f??r Vorselektion (im ReportHeader DB-Feldinhalte anzeigen)
    ADOTblVoreingabe.filtered := True;
    <!--fontc--></span><!--/fontc-->

    Thank you for your help >
  • LurkingKiwiLurkingKiwi Wellington, New Zealand
    edited 5:25PM
    It appears that if you create a variable using Report/Variables it is possible to assign an initial value to it.
    On the "Edit Variables" dialogue there is a pane at the bottom labelled "Expression:" where you can type something once a variable has been selected.
    This is stored in the fr3 file, but may become changed if you store a value into it from Delphi and then save the fr3 - I don't know.
    It probably should be a valid expression, such as a number or a quoted string which you could use directly on the report page.
    When I tried using -- as a value I could not prevent the preview from stopping with an expression error.

    Also, if you wish to use your current plan, you can access the names of a report's variables directly from Delphi without scanning the fr3 file.
    The Programmer's manual says (in Chapter 2, Working with a list of variables) to use
    procedure GetVariablesList(const Category: String; List: TStrings)
    from the frxVariables unit.

Leave a Comment