• Hello

    When I develop a program for the end user, they do not have access to the WP_Tools and WP_Reporter code to create a table as is done in the WP_Reporter calc demo. If the end user is to create a table that performs calculations, they need to be able to assign paragraph names and commands after the table has been created.

    The code at the bottom of this post is executed from a button.OnClick event and will assign a paragraph name and command to individual cells. I can confirm that the changes to the cells are made by displaying the paragraph name and formula by setting WPRichText1.ViewOptions := [wpShowParCalcNames,wpShowParCalcCommands]

    Problems:
    There are two issues that are present after assigning paragraph names and commands to the cells of a table to reproduce the WP_Reporter invoice demo.

    a) The text in the cells to which commands have been assigned can be manually changed. This should not occure and does not in the WP_Reporter invoice demo cells.

    b) If WPRichText1.RecalcText(true,true); is executed from a separate button.OnClick event, the recalculation is not performed.

    Suggestions as to what I am missing?

    TIA

    John


    Code to assign cell name and command is below

  • Thanks for the reply.

    I have the calculations and protection issues resolved.

    Using the "create name table" code as a template I have been able to create a number of table templates to automate the table creation process for the end user. Using the WPAT_PAR_Command and WPAT_PAR_Name parameters I have been able to import summary values in a cell from table A to a cell in table B via the recalc process as long as there is no overlap in cell names.

    Question 1: Is there a mechanism to via code to determine the number of tables that are present on a given document? This number would be helpful in assigning unique par names of newly created table cells.

    Question 2: When text is calculated, the results are expressed as floating point numbers. Is there a mechanism to convert the displayed text in a table cell or a WPTextObj to a currency?

    TIA

    John

    • Offizieller Beitrag
    Zitat

    Question 1: Is there a mechanism to via code to determine the number of tables that are present on a given document? This number would be helpful in assigning unique par names of newly created table cells.


    Please use a
    par := FirstPar;
    while par <>nil do ...
    loop for this. You can check par.ParagraphType for wpIsTable.

    Zitat

    Question 2: When text is calculated, the results are expressed as floating point numbers. Is there a mechanism to convert the displayed text in a table cell or a WPTextObj to a currency?


    Please check out the events OnCalcFormula and BeforeCalcFormula of TWPFormulaInterface

    and

    function TWPFormulaInterface.CalcFormula(RTFData: TWPRTFDataCollectionBase; // Owner collection
    par: TParagraph; // current paragraph or parent paragraph of field
    posinpar: Integer; // -1 for a paragraph formula, otherwise position of the object
    const formula: string;
    format: Integer; var value: Double; var strvalue: string): Boolean;

    in unit WPTblCalc.

  • Thanks for the reply

    As per your suggestion, the procedure below iterates through the paragraphs to obtain the table count. I also need to capture the table name associated with each paragraph that is of type wplsTable so it can be displayed to the end user. I have been unsuccessful in this endeavor. The line below with two asterisks seems like the logical solution, but it does not compile.

    Suggestions??

    TIA

    John

  • Support:

    In response to my question 2 above

    Zitat

    When text is calculated, the results are expressed as floating point numbers. Is there a mechanism to convert the displayed text in a table cell or a WPTextObj to a currency?

    Your reply was

    Zitat

    Please check out the events OnCalcFormula and BeforeCalcFormula of TWPFormulaInterface

    The HTML help file does list both functions, but I can find no example of the implementation of either function in any of the demos or the WP7manual. Could you please provide an example of how to implement the currency text formatting of table cells with numeric values such as are shown in the CalcTU demo?

    I greatly appreciate your efforts.

    John

    • Offizieller Beitrag

    To write the value as currency use this event handler.

    Code
    function TWPTableCalc.DoConvertValueToText(Sender: TObject; var text: string;  Format: Integer; Value: Double): Boolean;begin  text := FloatToStrF(Value, ffCurrency,10,2);  Result := true;end;

    It had been assigned to event ConvertValueToText.

    Please note that the EvalEngine is using the standard Delphi Round() method which is not necessarily correct for currencies, the same is true for FloatToStrF.

    I mentioned the unit WPTblCalc - there you find the method CalcFormula which is basically the reference (or default) implementation.

    I highly recommend to check out such units since the source is part of the documentation. In Delphi you can press ALT and click on a type, unit or procedure and it takes you there - you get an interactive manual.

  • Support

    I did look at the function TWPFormulaInterface.CalcFormula and saw that it called TWPFormulaInterface.WriteValueToText. In point of fact, I could substitute text := FloatToStrF(Value, ffCurrency,10,2); for text := FloatToStrF(value, ffFixed, 10, 2); on line 241 and get the result that I needed. I also saw that if IWPFormulaInterface.ConvertValueToText was assigned a function then that function would be implemented.

    Once I saw your implementation of DoConvertValueToText, I understood that I could declared the public function DoConvertValueToText and assign IWPFormulaInterface.ConvertValueToText := DoConvertValueToText in the OnCreate event of the form. I was then good to go.

    Thanks for your efforts

    John