variables / aggregates

edited 6:10PM in FastReport 4.0
Hi,

I'm sorry, this must be simple, but I'm unable to find out how to use aggregates in a header band...
I'm following the intructions in the manual (double pass & OnBeforePrint events with Get/Set)

So far I was't able to use my own declared variables eg <Group."Total"> & <Group."StartDate">
I do get errors as "could not convert variant of type (null) into type (OleStr). Unknown variable or datafield: Group."Total"

Set(<Group."Total">, SUM(...));

The variable does however exists...

I also noticed that you get another error when you haven't set an expression in your variable.

Finally I just used a datafield (as shown in the manual) and this works. At least for my totals.

Is this normal?? How can I use custom variables?

Further, how do I format a date variable ? Set(<Customers."CUSTOMER_DATE">, MIN(<Customers."INVOICE_DATE">, masterdetail1)

If I want to use this as Memo1.Text := 'Month : '+FormatDateTime('mmmm', Get(<Customers."CUSTOMER_DATE">). But this doesn't work. I get errors on this

Last question:
Is there a way to fill in variables and just use these inside a text object of the report gui? Do you realy need to use the code as in memo1.txt?

Thanks in advance,

Comments

  • edited 6:10PM
    There are 2 kinds of variables in FR. Categorized variable and non-categorized one.
    For the first kind you use Get() and Set()
    Look at this thread which deals with a similar problem.
    http://www.fast-report.com/en/forum/?p=/discussion/9134
    These variables can be referred to like table columns.

    The second kind you use like ordinary Pascal variable. However, they are run-time only as far as I can figure out one can only assign them to a memo component or a categorized variable in the script.
  • edited 6:10PM
    thanks for your reply.
    http://www.fast-report.com/en/forum/?p=/discussion/9134 [/url]
    These variables can be referred to like table columns.

    Thanks, but I found this thread already, but unfortunately I can't get it right... where is SaldoAtual in this case declared? As a variable in the script? Or as a variable in the report?
    technisoft wrote: »
    The second kind you use like ordinary Pascal variable. However, they are run-time only as far as I can figure out one can only assign them to a memo component or a categorized variable in the script.
    I tried this as well, but I seem to be unable to get it right in case with dates :-(.

    Anybody an idea how I can get a date 'variable' formatted into a header?

    Something like Memo1.Text := 'Month : '+FormatDateTime('mmmm', Get(<Customers."CUSTOMER_DATE">)
  • edited 6:10PM
    Ok. It took me some time to figure out what the writer meant in section 6.7 'Using aggregate functions in the script'. But I finally found a way to get this working.
  • edited 6:10PM
    it might be usefull for others, others can give feedback (or just tell that there is a much more simplistic way).

    Put three (in)visible text objects in the footer of the report with the following text:

    MIN(<Customer."CONSULT_DATE">,MasterData1)
    and
    MAX(<Customer."CONSULT_DATE">,MasterData1)
    and
    [SUM(<Customer."FEE">,MasterData1)]

    Than use the following script code:
    var
      tmpStr : String;
      ListPeriod, ListTotal : TStringList;
      i : integer;                                
        
    procedure GroupFooter1OnBeforePrint(Sender: TfrxComponent);
    begin                                                                                          
      tmpStr := '';                                         
      if not Engine.FinalPass then begin
        tmpStr := FormatDateTime('mmmm', MIN(<Customer."CONSULT_DATE">,MasterData1))                     
          + ' - ' + FormatDateTime('mmmm YYYY', MAX(<Customer."CONSULT_DATE">,MasterData1));
        ListPeriod.Add(tmpStr);
        tmpStr := Format('%2.2m', [SUM(<Customer."FEE">,MasterData1)] );
        ListTotal.Add(tmpStr);        
      end;                  
    end;
    
    procedure GroupHeader1OnBeforePrint(Sender: TfrxComponent);
    begin
      if Engine.FinalPass then begin
        Memo1.Text := 'Period: '+ListPeriod[i];           
        Memo18.Text := 'Total: '+ListTotal[i] + 'bla';        
      end;
      inc(i);                    
    end;
    
    procedure OnStartReport(Sender: TfrxComponent);
    begin
      ListPeriod := TStringList.Create;
      ListTotal := TStringList.Create;      
    end;
    
    procedure OnStopReport(Sender: TfrxComponent);
    begin
      ListTotal.Free;                                                   
      ListPeriod.Free;                          
    end;
    
    procedure Page1OnBeforePrint(Sender: TfrxComponent);
    begin
      i := 0;  
    end;
    
    begin
    
    end.
    
  • hsmhsm
    edited 6:10PM
    zifnabbe wrote: »
    it might be usefull for others, others can give feedback (or just tell that there is a much more simplistic way).

    Thank you. It was very useful for me.
    I have three nested groups and need to show an average score (from the detail section) for each group in their respective headers. I cannot use AVG() as not all the detail scores are available so I need to count them, sum then and do the average programatically at the end of each group.
    I messed around all day today trying to apply the example in the manual and the demo to my situation and could only get the outer group to behave properly.
    I can see that your solution using lists will do the job.
    Thanks for posting the solution. Too many people end a thread saying "I've fixed it now" without saying how!
    Howard

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.