WPREPORTER: Inserting Group Bands in code

  • Hi Julian,

    This is really a follow up to a previous question about selecting the contents of group bands (https://www.wpcubed.com/forum/viewtopic.php?t=1244).

    Basically, what I am trying to do is give the users a simple list report, and then give them the option of grouping the report on their choice of fields.

    e.g. the default report will be

    Code
    Header<DATA GROUP BAND>Record fields</DATA GROUP BAND>Footer

    and they can select a couple of fields to group the data on, and my code then needs to auto-format the report like this...

    I have written a test app which attempts to do this and is 90% of the way where, but I just need a little more help.

    I have emailed the sample app to "support@wptools.de" and I am more than happy for anyone else to have a copy of the source code if it helps. There are also a number of useful utility routines for TWPRichText and TWPSuperMerge in there.

    The point I am stuck at now is that I need the ability to remove the contents of a group band, but not the band itself.

    The problem is commented in the "InsertAutoGroup" routine in "uReportFuncs.pas".

    Thanks in advance,

    Hedley Muscroft
    Pioneer Software

    • Offizieller Beitrag

    Thanks for the code. I thgink this will be a valuable addition to the demo collection.

    First observations:
    A)
    par.DeleteParagraph; // <- delete the content of the DATA band

    Note, a text, header and footer band starts with the band paragraph followed by the text as sibling paragraphs (NextPar). SO to delete the text you need to to delete the NextPar while it is a text or table paragraph:

    Code
    // Clear the text, header of footer band which starts with 'par'
       while (par.NextPar<>nil) and
             (par.NextPar.ParagraphType in [wpIsTable, wpIsSTDPar]) do
                par.NextPar.DeleteParagraph;
      WPRichText1.ReformatAll(false, true); // AV possible without !

    B) WPRichText.InputString(#13);
    You should not mix InputString with DeleteParagraph unless you position the cursor, for example with an asignment to 'ActiveParagraph'. There are many functions to create text and fields in a paragraph directly, such as par.SetText, par.Append, par.AppendPairedObjects ect.

    C) par := SelectGroup(WPRichText, 'DATA');
    if par = nil then exit;
    WPRichText.SaveSelectionToStream(ms); // <- backup the DATA group contents

    This is not required. You can code:
    oldtext := grouppar.ChildPar.UnlinkParagraphList;

    now create the header and footer by creating new paragraphs (see my other post) and then use:
    lastinnerpar.NextPar := oldtext ;

    No stream operations are involved!

    Julian

    • Offizieller Beitrag

    So here is modified routine.

    Note how the new text is inserteded using the current writing attribute.

    I hope this helps,

    Julian

  • OK - I've tried to implement this, but just a couple of problems :-

    Firstly...

    Code
    par := WPSuperMerge.Bands.SelectGroup(WPRichText, 'DATA');

    I'm guessing that you must have implemented SelectGroup as part of the TWPBandManager object, because this won't compile. Please can you provide the code for this routine?

    Secondly, the new code doesn't seem to insert the headers/footers correctly.

    If I start with...

    Header
    <"DATA" GROUP BAND>
    Record fields
    </"DATA" GROUP BAND>
    Footer

    ...and I select just one "auto-group" field - let's say "category", the result is this (new lines in bold)...

    Header
    <"DATA" GROUP BAND>
    <HEADER BAND>
    FieldName : Category
    <FOOTER BAND>
    Count : count
    <"Category" GROUP BAND>

    Record fields
    </"Category" GROUP BAND>
    </"DATA" GROUP BAND>
    Footer

    The problem is that this doesn't merge correctly! The new header and footer bands need to be INSIDE the new "category" group band rather than above it. Also, for the supermerge to work, there needs to be a DATA band above the actual "Record fields" data.

    So, the finished template needs to be like this :-

    Header
    <"DATA" GROUP BAND>
    <"Category" GROUP BAND> <- above the header band
    <HEADER BAND>
    FieldName : Category
    <FOOTER BAND>
    Count : count
    <DATA BAND> <- may need to add DATA band

    Record fields
    </"Category" GROUP BAND>
    </"DATA" GROUP BAND>
    Footer

    I have tried jiggling your code around but I can't seem to get the new bands to insert inside the new group (I can move them to after but not inside!!).

    Also, how do we check to see if a DATA band already exists above the record data, and insert one if necessary?

    I know I'm asking a lot Julian, but this kind of reporting functionality will make a superb component even better!

    Thanks again for all your help,

    Hedley

    • Offizieller Beitrag

    Hi,

    "WPSuperMerge.Bands...." was inserted by mistake. I meant the function in your code. Next release will have a function FindGroup(name) which can be used as replacement.

    Zitat

    I can't seem to get the new bands to insert inside the new group (I can move them to after but not inside!!).

    This bands are created like this:
    bpar := par.AppendChild(nil);
    bpar.ParagraphType := wpIsReportHeaderBand;

    This means you can also create it inside the second group if you use the paragraph reference to that group instead of 'par'.

    basically I moved the block after "// and now insert a new group" up, assigned bpar to par and changed the line bpar.AppendChild(groupdata) to read par.AppendChild(groupdata); The line "par.AppendChild(nil).ParagraphType := wpIsReportDataBand;" is new, not really required.

    Regards,

    Julian