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:
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:
procedure TWPTableCalc.InvoiceDemoCell(RowNr, ColNr: Integer; par: TParagraph);
const prods : array[1..5] of string =
( 'Cool', 'Master', 'Hummer', 'High Performace', 'Better' );
begin
// Set the widths of the rows
case ColNr of
1 : par.ASet(WPAT_COLWIDTH_PC, 500); // % * 100 !
2 : par.ASet(WPAT_COLWIDTH_PC, 2500);
else
begin
par.ASet(WPAT_COLWIDTH_PC, 1400);
par.ASet(WPAT_Alignment, Integer(paralRight));
end;
end;
// Set the text and the cell names and commands
if RowNr=1 then // Header Row ------------------------------
begin
case ColNr of
1 : ;
2 : par.SetText('Product');
3 : par.SetText('Price');
4 : par.SetText('Amount');
5 : par.SetText('net');
6 : par.SetText('+VAT');
7 : par.SetText('total');
end;
par.ASetColor(WPAT_FGColor, $A0A0A0);
par.ASet(WPAT_ParProtected,1);
par.ASet(WPAT_Alignment, Integer(paralCenter));
end else
if RowNr=7 then // Footer Row ------------------------------
begin
par.ADel(WPAT_BorderWidth); // Delete the border width for ALL linese
par.ASet(WPAT_BorderWidthT, 40); // ANd set the top line to 40 twips
par.ASetAdd( WPAT_BorderFlags, WPBRD_DRAW_Top); // Add a flag!
// par.ParentRow.ASet(WPAT_BoxMinHeight, WPCentimeterToTwips(1.5));
par.ASet(WPAT_SpaceBefore, WPCentimeterToTwips(0.3));
par.ASet(WPAT_SpaceAfter, WPCentimeterToTwips(0.3));
par.ASet(WPAT_ParProtected,1);
case ColNr of
1 : ;
2 : ;
3 : ;
4 : ;
5 : begin
par.ASetStringProp(WPAT_PAR_COMMAND, 'PAR_NET');
end;
6 : begin
par.ASetStringProp(WPAT_PAR_COMMAND, 'PAR_VAT');
end;
7 : begin
par.ASetStringProp(WPAT_PAR_COMMAND, 'PAR_TOTAL');
par.ASetCharStyle(true, WPSTY_BOLD);
end;
end;
end else // Data Rows ------------------------------
begin
case ColNr of
1 : begin
par.SetText(IntToStr(RowNr-1));
par.ASet(WPAT_ParProtected,1);
end;
2 : par.SetText(prods[RowNr-1]);
3 : par.SetText(IntToStr(Random(1000)+1));
4 : par.SetText(IntToStr(Random(3)+1));
5 : begin // we multipy the count with the price to get the net amount
par.ASetStringProp(WPAT_PAR_COMMAND, 'left(2)*left(1)');
par.ASetStringProp(WPAT_PAR_NAME, 'PAR_NET');
par.ASet(WPAT_ParProtected,1);
end;
6 : begin // we multiply the net with 0.16 to get the VAT
par.ASetStringProp(WPAT_PAR_COMMAND, 'left(1)*0.16');
par.ASetStringProp(WPAT_PAR_NAME, 'PAR_VAT');
par.ASet(WPAT_ParProtected,1);
end;
7 : begin // we add the net amout + the VAT to get the total
par.ASetStringProp(WPAT_PAR_COMMAND, 'left(2)+left(1)');
par.ASetStringProp(WPAT_PAR_NAME, 'PAR_TOTAL');
par.ASet(WPAT_ParProtected,1);
end;
end;
end;
end;
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.