set variable to memo in double pass group footer

edited 9:26AM in FastReport 4.0
Hello to all,
Why does the memo field in the group footer equal to the last value of a variable I am using as a accumulating.
Sample: script

procedure MasterData1OnBeforePrint(Sender: TfrxComponent);
begin
if Engine.FinalPass=false then begin
lhrs:=lhrs+<adoquery1."QTY">;
end;
end;

procedure GroupFooter2OnBeforePrint(Sender: TfrxComponent);
begin
if Engine.FinalPass=false then begin
memo1.text:=formatfloat('#.00',lhrs);
end;

The memo field is set to the last value lhrs is for all groupfooter breaks.
It should be a different value for each grouped item.

Can anyone elaborate.

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 9:26AM
    assuming you declared your variable at the beginning of the script before any procedures.
    var
    lhrs: integer
    procedure MasterData1OnBeforePrint(Sender: TfrxComponent);
    begin
    lhrs:=lhrs+<adoquery1."QTY">;
    end;


    begin
    lhrs:=0; {could initilize here}
    end.
    YOU MUST reinitialize its value to 0 in the correct group header.
    then all you need to do is to have [lhrs] in the memo and set its display format
    no need for code in the footer.
  • edited January 2010
    Here is the code as I have it.

    Code:
    var
     lhrs,lcost, mhrs, mcost,estc,destc, dcost,estq :double;
     destq, tlestq, tlestc, tmestc, thrs : double;                                          
     lqlist, lclist, mclist,elqlist,elclist,emclist,jlist : TStringlist;
     i : integer;
     cjob : string;                                 
    
    procedure MasterData1OnBeforePrint(Sender: TfrxComponent);
    begin
      if Engine.FinalPass=false then begin                             
      if length(<adoquery1."PART_WC">)=2 then begin                        
       lhrs:=lhrs+<adoquery1."QTY">;  
       lcost:=lcost+<adoquery1."AMOUNT">;
       dcost:=dcost+<adoquery1."AMOUNT">;           
      end
      else begin
       mhrs:=mhrs+<adoquery1."QTY">;  
       mcost:=mcost+<adoquery1."AMOUNT">;
       dcost:=dcost+<adoquery1."AMOUNT">;             
      end;
      end;            
    end;
    
    procedure GroupFooter2OnBeforePrint(Sender: TfrxComponent);
    begin
    if Engine.FinalPass=false then begin    
      memo1.text:=formatfloat('#.00',lhrs);    -----> all of these memo fields have the same value on all group breaks.        
      memo13.text:=formatfloat('#.00',lcost);
      memo21.text:=formatfloat('#.00',mhrs);        
      memo22.text:=formatfloat('#.00',mcost);
      memo30.text:=formatfloat('#.00',tlestq);
      memo31.text:=formatfloat('#.00',tlestc);
      memo32.text:=formatfloat('#.00',tmestc);
      if (lcost=0) and (mcost=0) then begin             
       memo44.text:='00';  
       memo45.text:='00';
      end                 
      else begin                              
       memo44.text:=formatfloat('00',(lcost/(lcost+mcost))*100);    
       memo45.text:=formatfloat('00',(mcost/(lcost+mcost))*100);
      end;                 
      memo43.text:=formatfloat('#.00',lcost+mcost);
      memo46.text:=formatfloat('#.00',tlestc+tmestc);             
      jlist.add(<Adoquery1."JOB">);            
      lclist.add(Floattostr(lcost));
      lqlist.add(floattostr(lhrs));
      mclist.add(floattostr(mcost));
      elqlist.add(floattostr(tlestq));
      elclist.add(floattostr(tlestc));                                                                    
      emclist.add(floattostr(tmestc));      
      lhrs:=0;
      lcost:=0;
      mhrs:=0;
      mcost:=0;
      tlestq:=0;
      tlestc:=0;
      tmestc:=0;
    end;              
    end;
    
    procedure Memo39OnBeforePrint(Sender: TfrxComponent);
    var
     wh,th,wlc,tlc : extended;
     ws : string;                                
    begin
     if Engine.FinalPass then begin
          
      if length(<Adoquery1."PART_WC">)=2 then begin
       th:=0;
       wh:=0;                 
       th:=strtofloat(trim(lqlist[i]));
       if memo19.text<>'' then                                                     
       wh := strtofloat(trim(memo19.text));
       if th=0 then th:=1;                                                     
       memo35.text:=formatfloat('00',(wh/th)*100);
       wlc:=0;
       if memo20.text<>'' then                                                     
       wlc := strtofloat(trim(memo20.text));
       //memo36.text:=jlist[i]+'L:'+lclist[i];                                                           
       tlc := strtofloat(trim(lclist[i]));
       if tlc=0 then tlc:=1;                                                     
       memo34.text:=formatfloat('00',(wlc/tlc)*100);
       th:=strtofloat(trim(elqlist[i]));
       if ESTQTY.text<>'' then                                                     
       wh:=strtofloat(trim(ESTQTY.text))
       else
       wh:=0;                 
       if th=0 then th:=1;     
       memo33.text:=formatfloat('00',(wh/th)*100);
       th:=strtofloat(trim(elclist[i]));
       if ESTCOST.text<>'' then                                                     
       wh:=strtofloat(trim(ESTCOST.text))
       else
       wh:=0;                 
       if th=0 then th:=1;     
       memo39.text:=formatfloat('00',(wh/th)*100);                         
      end
      else begin
       th:=0;
       wh:=0;
       if memo21.text<>'' then                                                       
       th:=strtofloat(trim(lqlist[i]));
       if memo19.text<>'' then                                                       
       wh := strtofloat(trim(memo19.text));
       if th=0 then th:=1;                                                  
       memo35.text:=formatfloat('00',(wh/th)*100);
       //memo36.text:=jlist[i]+'M:'+emclist[i];       
       wlc:=0;
       tlc:=0;
       if memo20.text<>'' then                                                     
       wlc := strtofloat(trim(memo20.text));                              
       tlc := strtofloat(trim(mclist[i]));
       if tlc=0 then tlc:=1;                                                  
       memo34.text:=formatfloat('00',(wlc/tlc)*100);
      
       th:=strtofloat(trim(emclist[i]));
       if ESTCOST.text<>'' then                                                     
       wh:=strtofloat(trim(ESTCOST.text))
       else
       wh:=0;                 
       if th=0 then th:=1;     
       memo39.text:=formatfloat('00',(wh/th)*100);       
      end;
           
     end;                          
    end;
    
    
    procedure frxReport1OnStartReport(Sender: TfrxComponent);
    begin
      jlist := TStringlist.create;                                                                   
      lclist := TStringlist.create;
      lqlist := TStringlist.create;
      mclist := TStringlist.create;
      elclist := TStringlist.create;
      elqlist := TStringlist.create;
      emclist := TStringlist.create;                                                                  
    end;
    
    procedure frxReport1OnStopReport(Sender: TfrxComponent);
    begin
      jlist.free;                                           
      lclist.free;
      lqlist.free;
      mclist.free;
      elclist.free;
      elqlist.free;
      emclist.free;                                    
    end;
    
    procedure Memo15OnBeforePrint(Sender: TfrxComponent);
    var
     wh,th,wlc,tlc : extended;
     ws : string;    
    begin
     if Engine.FinalPass then begin
          
      if length(<Adoquery1."PART_WC">)=2 then begin
       wlc:=0;                 
       if memo18.text<>'' then
       wlc := strtofloat(trim(memo18.text));                                                   
       tlc := strtofloat(trim(lclist[i]));
       if tlc=0 then tlc:=1;                                                     
       memo15.text:=formatfloat('00',(wlc/tlc)*100);
       tlc := strtofloat(trim(elqlist[i]));
       wlc:=0;
       if memo29.text<>'' then                                                     
       wlc := strtofloat(trim(memo29.text));
       if tlc=0 then tlc:=1;                                                    
       memo42.text:=formatfloat('00',(wlc/tlc)*100);                   
      end
      else begin
    
      end;
            
     end;           
    end;
    
    
    procedure GroupHeader2OnBeforePrint(Sender: TfrxComponent);
    begin
     if Engine.FinalPass then begin
      if cjob='' then cjob:=<Adoquery1."JOB">;                                                              
      if <Adoquery1."JOB"><>cjob then begin
       cjob:=<Adoquery1."JOB">;                                                      
       inc(i);
      end;
     end;                 
    end;
    
    procedure ESTCOSTOnAfterPrint(Sender: TfrxComponent);
    begin
      if length(<ADOQuery1."PART_WC">)=2 then begin
       tlestq:=tlestq+StrtoFloat(trim(ESTQTY.text));
       tlestc:=tlestc+StrtoFloat(trim(ESTCOST.text));                                     
      end
      else            
       tmestc:=tmestc+StrtoFloat(trim(ESTCOST.text));  
    end;
    
    procedure PageHeader1OnBeforePrint(Sender: TfrxComponent);
    begin
      if get('BDATE')<>'' then
       memo8.text:=get('BDATE')+' - '+get('EDATE');
      if get('RTYPE')='C' then                                                   
      memo11.text:='Current'
      else
      memo11.text:='Archive';                                                  
    end;
    
    procedure MasterData2OnBeforePrint(Sender: TfrxComponent);
    begin
      if Engine.FinalPass=false then begin                             
      if length(<adoquery2."PART_WC">)=2 then begin                        
       lhrs:=lhrs+<adoquery2."QTY">;  
       lcost:=lcost+<adoquery2."AMOUNT">;
       dcost:=dcost+<adoquery2."AMOUNT">;
       tlestq:=tlestq+<adoquery2."EQTY">;
       tlestc:=tlestc+<adoquery2."ECOST">;         
      end
      else begin
       mhrs:=mhrs+<adoquery2."QTY">;  
       mcost:=mcost+<adoquery2."AMOUNT">;
       dcost:=dcost+<adoquery2."AMOUNT">;
       tmestc:=tmestc+<adoquery2."ECOST">;         
      end;
      end;  
    end;  
    
    begin
      i:=0;                           
    end.
    
  • edited January 2010
    Corrected problem with change to code.
    Logic problem was changed to fill memo fields on second pass.
    var
     lhrs,lcost, mhrs, mcost,estc,destc, dcost,estq :double;
     destq, tlestq, tlestc, tmestc, thrs : double;                                          
     lqlist, lclist, mclist,elqlist,elclist,emclist,jlist : TStringlist;
     i : integer;
     cjob : string;                                 
    
    procedure MasterData1OnBeforePrint(Sender: TfrxComponent);
    begin
      //if Engine.FinalPass=false then begin                    ---------------> removed to allow calculate to occur on both passes.         
      if length(<adoquery1."PART_WC">)=2 then begin                        
       lhrs:=lhrs+<adoquery1."QTY">;  
       lcost:=lcost+<adoquery1."AMOUNT">;
       dcost:=dcost+<adoquery1."AMOUNT">;           
      end
      else begin
       mhrs:=mhrs+<adoquery1."QTY">;  
       mcost:=mcost+<adoquery1."AMOUNT">;
       dcost:=dcost+<adoquery1."AMOUNT">;             
      end;
      //end;            
    end;
    
    procedure GroupFooter2OnBeforePrint(Sender: TfrxComponent);
    begin
    if Engine.FinalPass then begin                    -----------------> print this section only on final pass.
      memo1.text:=formatfloat('#.00',lhrs);        
      memo13.text:=formatfloat('#.00',lcost);
      memo21.text:=formatfloat('#.00',mhrs);        
      memo22.text:=formatfloat('#.00',mcost);
      memo30.text:=formatfloat('#.00',tlestq);
      memo31.text:=formatfloat('#.00',tlestc);
      memo32.text:=formatfloat('#.00',tmestc);
      if (lcost=0) and (mcost=0) then begin             
       memo44.text:='00';  
       memo45.text:='00';
      end                 
      else begin                              
       memo44.text:=formatfloat('00',(lcost/(lcost+mcost))*100);    
       memo45.text:=formatfloat('00',(mcost/(lcost+mcost))*100);
      end;                 
      memo43.text:=formatfloat('#.00',lcost+mcost);
      memo46.text:=formatfloat('#.00',tlestc+tmestc);
    end;                                        -------------> moved end to this point to allow accumulators and reinitialization of variables.
      jlist.add(<Adoquery1."JOB">);            
      lclist.add(Floattostr(lcost));
      lqlist.add(floattostr(lhrs));
      mclist.add(floattostr(mcost));
      elqlist.add(floattostr(tlestq));
      elclist.add(floattostr(tlestc));                                                                    
      emclist.add(floattostr(tmestc));      
      lhrs:=0;
      lcost:=0;
      mhrs:=0;
      mcost:=0;
      tlestq:=0;
      tlestc:=0;
      tmestc:=0;
                  
    end;
    
    procedure Memo39OnBeforePrint(Sender: TfrxComponent);
    var
     wh,th,wlc,tlc : extended;
     ws : string;                                
    begin
     if Engine.FinalPass then begin
          
      if length(<Adoquery1."PART_WC">)=2 then begin
       th:=0;
       wh:=0;                 
       th:=strtofloat(trim(lqlist[i]));
       if memo19.text<>'' then                                                     
       wh := strtofloat(trim(memo19.text));
       if th=0 then th:=1;                                                     
       memo35.text:=formatfloat('00',(wh/th)*100);
       wlc:=0;
       if memo20.text<>'' then                                                     
       wlc := strtofloat(trim(memo20.text));
       //memo36.text:=jlist[i]+'L:'+lclist[i];                                                           
       tlc := strtofloat(trim(lclist[i]));
       if tlc=0 then tlc:=1;                                                     
       memo34.text:=formatfloat('00',(wlc/tlc)*100);
       th:=strtofloat(trim(elqlist[i]));
       if ESTQTY.text<>'' then                                                     
       wh:=strtofloat(trim(ESTQTY.text))
       else
       wh:=0;                 
       if th=0 then th:=1;     
       memo33.text:=formatfloat('00',(wh/th)*100);
       th:=strtofloat(trim(elclist[i]));
       if ESTCOST.text<>'' then                                                     
       wh:=strtofloat(trim(ESTCOST.text))
       else
       wh:=0;                 
       if th=0 then th:=1;     
       memo39.text:=formatfloat('00',(wh/th)*100);                         
      end
      else begin
       th:=0;
       wh:=0;
       if memo21.text<>'' then                                                       
       th:=strtofloat(trim(lqlist[i]));
       if memo19.text<>'' then                                                       
       wh := strtofloat(trim(memo19.text));
       if th=0 then th:=1;                                                  
       memo35.text:=formatfloat('00',(wh/th)*100);
       //memo36.text:=jlist[i]+'M:'+emclist[i];       
       wlc:=0;
       tlc:=0;
       if memo20.text<>'' then                                                     
       wlc := strtofloat(trim(memo20.text));                              
       tlc := strtofloat(trim(mclist[i]));
       if tlc=0 then tlc:=1;                                                  
       memo34.text:=formatfloat('00',(wlc/tlc)*100);
      
       th:=strtofloat(trim(emclist[i]));
       if ESTCOST.text<>'' then                                                     
       wh:=strtofloat(trim(ESTCOST.text))
       else
       wh:=0;                 
       if th=0 then th:=1;     
       memo39.text:=formatfloat('00',(wh/th)*100);       
      end;
           
     end;                          
    end;
    
    
    procedure frxReport1OnStartReport(Sender: TfrxComponent);
    begin
      jlist := TStringlist.create;                                                                   
      lclist := TStringlist.create;
      lqlist := TStringlist.create;
      mclist := TStringlist.create;
      elclist := TStringlist.create;
      elqlist := TStringlist.create;
      emclist := TStringlist.create;                                                                  
    end;
    
    procedure frxReport1OnStopReport(Sender: TfrxComponent);
    begin
      jlist.free;                                           
      lclist.free;
      lqlist.free;
      mclist.free;
      elclist.free;
      elqlist.free;
      emclist.free;                                    
    end;
    
    procedure Memo15OnBeforePrint(Sender: TfrxComponent);
    var
     wh,th,wlc,tlc : extended;
     ws : string;    
    begin
     if Engine.FinalPass then begin
          
      if length(<Adoquery1."PART_WC">)=2 then begin
       wlc:=0;                 
       if memo18.text<>'' then
       wlc := strtofloat(trim(memo18.text));                                                   
       tlc := strtofloat(trim(lclist[i]));
       if tlc=0 then tlc:=1;                                                     
       memo15.text:=formatfloat('00',(wlc/tlc)*100);
       tlc := strtofloat(trim(elqlist[i]));
       wlc:=0;
       if memo29.text<>'' then                                                     
       wlc := strtofloat(trim(memo29.text));
       if tlc=0 then tlc:=1;                                                    
       memo42.text:=formatfloat('00',(wlc/tlc)*100);                   
      end
      else begin
    
      end;
            
     end;           
    end;
    
    
    procedure GroupHeader2OnBeforePrint(Sender: TfrxComponent);
    begin
     if Engine.FinalPass then begin
      if cjob='' then cjob:=<Adoquery1."JOB">;                                                              
      if <Adoquery1."JOB"><>cjob then begin
       cjob:=<Adoquery1."JOB">;                                                      
       inc(i);
      end;
     end;                 
    end;
    
    procedure ESTCOSTOnAfterPrint(Sender: TfrxComponent);
    begin
      if length(<ADOQuery1."PART_WC">)=2 then begin
       tlestq:=tlestq+StrtoFloat(trim(ESTQTY.text));
       tlestc:=tlestc+StrtoFloat(trim(ESTCOST.text));                                     
      end
      else            
       tmestc:=tmestc+StrtoFloat(trim(ESTCOST.text));  
    end;
    
    procedure PageHeader1OnBeforePrint(Sender: TfrxComponent);
    begin
      if get('BDATE')<>'' then
       memo8.text:=get('BDATE')+' - '+get('EDATE');
      if get('RTYPE')='C' then                                                   
      memo11.text:='Current'
      else
      memo11.text:='Archive';                                                  
    end;
    
    procedure MasterData2OnBeforePrint(Sender: TfrxComponent);
    begin
      if Engine.FinalPass=false then begin                             
      if length(<adoquery2."PART_WC">)=2 then begin                        
       lhrs:=lhrs+<adoquery2."QTY">;  
       lcost:=lcost+<adoquery2."AMOUNT">;
       dcost:=dcost+<adoquery2."AMOUNT">;
       tlestq:=tlestq+<adoquery2."EQTY">;
       tlestc:=tlestc+<adoquery2."ECOST">;         
      end
      else begin
       mhrs:=mhrs+<adoquery2."QTY">;  
       mcost:=mcost+<adoquery2."AMOUNT">;
       dcost:=dcost+<adoquery2."AMOUNT">;
       tmestc:=tmestc+<adoquery2."ECOST">;         
      end;
      end;  
    end;  
    
    begin
      i:=0;                           
    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.