How can i change a variable value?

theodoretheodore Greece
edited 6:06PM in FastReport 2.xx VCL
Hello
I need to use a variable for a report, then pass it to the report. After that the report has to change the value of that variable and after report printing to access the changed value of the variable.
Can i do that and how?
I know how to pass and use the variable, i tried changing the value of the variable by putting in an obp event looking like variable:=12345, with the variable name without brackets. I can see the changed value by referencing the variable on a memo using [variable] but when back in program the variable value seems unchanged
Thanks

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 6:06PM
    Hi Theodore
    in the report create a userfunction in an obp of the band or script of memo
    ie myval := myuserfunctionname(p1,p2,p3); you can pass up to 3 parameters out to Delphi at once and it will return 1 result, which you can use or ignore
    your parameters can be a variable datafield or a value just enclose in [] and separate with commas.

    you also have to write an onuserfunction event handler for the report component itself in Delphi to handle the values passed out and set the return the value.

    Create User function for the report component.

    procedure TForm1.frReport1UserFunction(const Name: string; p1, p2,
    p3: Variant; var Val: Variant);
    var
    s: string; // declare variables of required type.
    i: int
    d1: date
    begin
    if AnsiCompareText(Name, 'myuserfunctionname') = 0 then
    begin

    s:= frparser.calc(p1); //get value from report and stor in delphi variable
    i:= frparser.calc(p2);
    d1:= frparser.calc(p3);
    code to parse and do whatever
    val := whatever external delphi function(); // return result to report in val
    end;

    end;
    you can also make use of the onprintreport event of the report component
    it fires once each time a report is sent to the printer.
    regards ;)
  • edited 6:06PM
    FAQ:

    2.25. How to pass a value to the report?

    There are several methods to do this. First is to use global object
    frVariables (defined in FR_Class unit):

    frVariables := 10;

    This code creates a new variable with 'My variable' name and value = 10.
    This method is best to pass static data to the report.


    (can I pass data from report to the program?)

    Use frVariables object. If you write the following code in any script:

    MyVariable := 10

    then in your program you can use this code to retrieve MyVariable value:
    v := frVariables;
  • theodoretheodore Greece
    edited 6:06PM
    Got it...
    Thanks....

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.