Last record of group

Hi

I need to "switch" off (i.e. Set visible property to False or True) a Line object in a master band, but only if the master band record is the last record in a group. Any ideas / suggestions?

Report layout:
Group header band
Master band (<<-- if this is the last record for the current group, set Line object Visible property to False else set it to True)

Any ideas?

TIA
Regan

Comments

  • Anu de DeusAnu de Deus Hampshire, UK
    edited 6:16PM
    Tricky one.
    I'd try this:
    Set it to be a DoblePass report, first of all.
    Then all the following is in the scripts of the report:
    Create a global variable to count the number of records, let's say TotalRecs, and one for the current rec, CurrentRecCounter, initialise them with 0.
    Then on the OnBeforePrintEvent of your MasterData band you increase the counter IF it's the first pass, or if it's the FINAL pass, then you set the visibility of your line to true or false:

    MasterData.OnBeforePrintEvent
    begin
    if not Engine.FinalPass then
    inc(TotalRecs)
    else begin
    inc(CurrentRecCounter);
    if CurrentRecCounter >= TotalRecs then
    Line1.visible := false
    else
    Line1.visible := true;
    end;
    end;


    Alternatively, you can skip the inc(TotalRecs) line and initialise it directly with
    TotalRecs := Dataset.recordcount;

    I hope it gives you some ideas.
  • Anu de DeusAnu de Deus Hampshire, UK
    edited 6:16PM
    Also, I think I saw something in the User help files (pdf), go the section that talks about the child objects, you might find something to help with code like this:
    child1.visible := not dataset.eof;

    where your line is in the child1 band.
  • gordkgordk St.Catherines On. Canada.
    edited 6:16PM
    Basic
    retrieve the recordcount of the dataset store in a variable
    when line# variable = recordcount turn off what you want.

    Grouping

    since you are using grouping you will have to make the report 2 pass store the count in an array
    just like storing a total to print in the header, only store the count.
    as Anu de Deus has suggested.
  • edited 6:16PM
    Hi,

    Thanks for the help and ideas. It pointed me in the right direction. In my final solution, I followed the "Total in Group header" example somewhat.
    Not fully understanding how the variables were being reset in the events, I had to play around initially. I also added a group footer, which I didn't need (so I just set its Visible property to False on the FinalPass - not sure if it needs to be visible for the OnBeforePrint to be called, so left it there for the first pass).
    Anyways, below is the code I finally implemented:

    var
    slGrpList: TStringList;
    iGrpRecCount: integer;
    iGrpCount: integer;

    procedure frxInvoiceOnStartReport(Sender: TfrxComponent);
    begin
    iGrpRecCount:= 0;
    iGrpCount:= 0;
    iRecID := 0;
    slGrpList:= TStringList.Create;
    end;

    procedure frxInvoiceOnStopReport(Sender: TfrxComponent);
    begin
    slGrpList.Free;
    end;

    procedure GroupFooter1OnBeforePrint(Sender: TfrxComponent);
    begin
    if not Engine.FinalPass then
    begin
    List.Add(IntToStr(iGrpRecCount));
    iGrpRecCount:= 0;
    end;
    Inc(iGrpCount);
    iRecID := 0;
    if Engine.FinalPass then
    GroupFooter1.Visible := False;
    end;


    procedure MasterData11OnBeforePrint(Sender: TfrxComponent);
    begin
    if not Engine.FinalPass then
    begin
    inc(iGrpRecCount);
    end
    else
    begin
    Inc(iRecID );
    if iRecID = StrToInt(List[iGrpCount-List.Count]) then // note this, the iGrpCount variable was always working out to twice the actual list count, hence the subtraction
    Line33.visible := false
    else
    Line33.visible := true;
    end;

    Anyway, thanks for the suggestions. I got it to work!
    Regan
  • edited 6:16PM
    A maybe dirty but simpler one?
    procedure MasterData1OnBeforePrint(Sender: TfrxComponent);
    var 
      OldGroupValue :Integer;
    begin
      OldGroupValue := <Data."GroupID">;                                                    
      MasterData1.DataSet.Next;
      Line33.visible := (OldGroupValue = <Data."GroupID">) and not MasterData1.DataSet.Eof;
      If not MasterData1.DataSet.Eof then                                 
        MasterData1.DataSet.Prior;                                                                   
    end;
    

    No need 2 pass, no need variable, simple code in one function.
    I am not very familiar with FR coding though so I don't know it had bad effect or not...

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.