About table.GetObjList - Calculating fields with WPReporter

  • Taken for WPReporter:
    { This is only a dem to show how values on a page can be calculated. To
    calculate values in a table you can use
    table.GetObjList }
    // We don't want to use this in the first editor!

    Hi there,

    1. I am looking forward to see a demo of table.GetObjList function, cause I cannot get it to work properly.

    2. I cant find good enough information on how to use formulas with the Report band properies - Will it be possible to sum fields at runtime?

    3. What I am dealing with right now, is I am getting some data from a database, these I want to sum at every line like this:

    Line 1: <<amount>> <<price>> [<<amount>> * <<price>>]
    Line 2: <<amount>> <<price>> [<<amount>> * <<price>>]
    Line 3: <<amount>> <<price>> [<<amount>> * <<price>>]
    Line 4: [sum of line 1+2+3]

    amount and price comes from the database, last one is calculated, and I want the last one to be calculated by WPRepporter not by database.


    Thank you very much, keep up the good work - cause it is good work!

    Dennis
    ________
    Lincoln Cosmopolitan specifications

    Einmal editiert, zuletzt von itognet (1. Februar 2011 um 12:03)

    • Offizieller Beitrag

    Hi,

    thanks for the compliment.

    The GetObjList is a one of the more special procedures:
    procedure GetObjList(mask: TWPTextObjTypes; List: TList; LastChildPar: TParagraph = nil; RequiredName: string= '');

    This procedure collects all objects of a certain type with a certain name which are used in this paragraph or any of its children paragraphs including the child paragraph 'LastChildPar'.

    You can use it for tables but also for table rows, for example to list all merge fields in a table row.

    In your case, "I want the last one to be calculated by WPRepporter not by database" the best solution is to add a field which is not in the database and provide its contents trough the GetText event. You have to sum this value up in your code, set it to 0 when you create the query and sum it up for each new row.

    WPTools would be able to calculate this sum at runtime in the editor using the WPFormualInterface. But this is more an editing feature (I useit to calculate invoices), not for WPReporter. Here usually static texts are used.

    To have a sum with the WPFormulaInterface apply a certain NAME to all cells which should be sumed up. Use the same name as 'command' in the one cell which should display this sum. The goof thing as that this kind of relations are not broken by inserting rows.

    The cells with the NAME can also be calculated- Here commands such as "left(2)*left(1)" would be possible - that would produce the same result as you example. Only the columns ammount and price are editable. The demo WPReporter\TableCalc shows how this works.

    But as said - with WPReporter better use fixed values.

    Julian Ziersch
    [/b]

  • Can you explain this a bit better:
    You wrote: To have a sum with the WPFormulaInterface apply a certain NAME to all cells which should be sumed up. Use the same name as 'command' in the one cell which should display this sum.

    What do you mean about 'command', is this a speciel way to create a mergefield?

    What can I write in start code, prepare code and end code in the formula editor.

    How should I apply the formula?

    The reason for asking is that I cant find information on this great issue.
    Is there an example or a better description for using the formula tab somewhere?


    Thanks
    Dennis
    ________
    health store

    Einmal editiert, zuletzt von itognet (1. Februar 2011 um 12:03)

    • Offizieller Beitrag

    What is meant was very simple.
    create a varianble called
    sum : Extended;
    When you start the query set this to 0
    for each row add a certain field

    and pass the value of this variable when a certain verianble name is used in a merge field. This does NOT use StartCode/EndCode etc. I think it is much easier to use and much more reliable.


    The WPFormulaInterface cannot be used with WPReporter. The code is from the TableCalc demo, it shows how to create an invoice:

    Code
    procedure TWPTableCalc.InvoiceDemoClick(Sender: TObject);var par : TParagraph;    obj : TWPTextObj;begin  WPRichText1.Clear;  WPRichText1.CheckHasBody;  par := WPRichText1.ActiveParagraph;  par.SetText('This are the ordered products:');  par.ASet(WPAT_ParProtected,1);  par.ASetBorderFlags(WPBRD_DRAW_Bottom);  // ---------------------------------------------------------------------------  par := WPRichText1.TableAdd(7,7,[wptblActivateBorders,wptblAppendTableAtEnd],nil, InvoiceDemoCell);  // ---------------------------------------------------------------------------  par := WPRichText1.ActiveText.AppendPar(nil, par);  par := WPRichText1.ActiveText.AppendPar(nil, par);  par.SetText('Please pay ');  obj := par.AppendNewObject(wpobjTextObject,false, false);  obj.Name := 'CALC';  obj.Source := 'PAR_TOTAL';  obj.Params := '???';  // ---------------------------------------------------------------------------  WPRichText1.RecalcText(true,true);end;

    This code uses this callback routine to fill in the cell text and properties:

    You see how par.ASetStringProp is used to set the command and the name.

    In this example using the text 'PAR_TOTAL' as command of a certain table cell will fill in the sum of all cells which have 'PAR_TOTAL' as their name.