Using A Group Sum In The MasterData Calc

PixelPointerPixelPointer Vaughan, Ontario
edited 12:33AM in FastReport 3.0
I am new to Fast Reports, but I am very used to Crystal Reports. I would like to be able to use the summary of my group to calculate each items percentage of the sum. Does anyone know how I can do that? ;)

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 12:33AM
    first make the report 2 pass assuming we will display the % in a memo on the mdband create a variable of type extended on the code page ie "mypct" it will be used to display the value in the memo [mypct] initialize it to 0 at the start of the report. store the aggregate sum in an array whose index value is set in the group header, on the first pass. you can then write code in the obp event of the mdband to modify the variables value.
    if engine.finalpass then mypct := <datafield."name"> \ array(index)
  • PixelPointerPixelPointer Vaughan, Ontario
    edited 12:33AM
    Thank you very much Gord for your assistance. I am doing my best with this scripting stuff, but not having the best of luck. Are there sample scripts around here, to kinda give me a better understanding of the scripting? I have done some C, C#, and VB programming in the past, so I am not completely unfamiliar with programming. The arrays are throwing me off a little. Within the script, can I set up a dynamic array variable with which I might re-dimension, while preserving the previously added aggregate values? Actually, I was wondering why it does not work to simply declare a global variable, and then in the obp of the mdband, add the field values to the variable on first pass, then perform the calcualtion on second pass. To me, this logically makes sense, but I tried that, and then ended up out here posting my question.

    I grabbed a script from the FR site, and attempted to bastardize it for my own purposes, but I keep recieving an issue with variable types:
     
    var
    List: TStringList;
    i: Integer;
    procedure FFReportOnStartReport(Sender: TfrxComponent);
    begin
    List := TStringList.Create;
    end;
    procedure FFReportOnStopReport(Sender: TfrxComponent);
    begin
    List.Free;
    end;
    procedure Page1OnBeforePrint(Sender: TfrxComponent);
    begin
    i := 0;
    end;
    procedure MasterData1OnBeforePrint(Sender: TfrxComponent);
    begin
    if Engine.FinalPass then
    memPercentTotal.Text := <Price> / StrToFloat(List[i]);
    
    end;
    procedure gfSummaryGroupOnBeforePrint(Sender: TfrxComponent);
    begin
    List.Add(FloatToStr(<SUM(<Price>,MasterData1)>));
    Inc(i);
    end;
    begin
    end.
    

    <Price> is the field that I am using to sum, and is the basis for my calculations.
  • gordkgordk St.Catherines On. Canada.
    edited 12:33AM
    run the main demo look under dialogs and script category at the grouptotalsin header report to see how we gathered the total from the footer into the array created using the set method in the event of the footer and how we transfered it to the memo in the obp of the header using the get method.
    the principal is the same except you won't need to use vartostr function just transfer value to the var you created
    create a var mytot at start of code page, in blank begin end block initialize it to 1
    then the memo can contain the expression [datafield/variable]
  • PixelPointerPixelPointer Vaughan, Ontario
    edited 12:33AM
    That was great! Thank you so much for your help!!!

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.