Problem with saving a table

  • Hello Julian,

    I have a problem with wprichtext1. I have just a table in my WpRichText and I would like to save it and to reload it. I created a short example here.
    When I load the file RTF, the file is displayed but the table does no longer exist.
    In the following example, before saving, anything is ok.
    After reloading, the table name is not displayed and rowCount is 0.
    But when I display in notepad the rtf file, all of the informations are here !!!

    Any help is welcome.
    Bye

  • of course I tried to do it.

    Guess what ?

    It doesn't work.

    I also tried wprichtext1.clear, and it doesn't work

    so my question is the following: how can I save a rtf which has just a table inside and to download it back and to have as many rows in the table as before ? and to have also the name of the table, because when I load the rtf file, the table has no longer any name...

    I gave here a very simple code, so may be you have 5 minutes to test it and to tell me what is wrong

    Thanks in advance

  • Julian,

    it really doesn't work.

    I downloaded the latest version of wptools 5.xx.

    I have Delphi 7 on windows xp SP 2

    after loading, the table has 0 rows and the table has no name

    could I send you my small project (the one above, with 3 lines in a table), and the exe file ?

    you will see yourself it doesn't work

    what's strange is anything seems correct in the rtf file, 3 rows with one cell per row and the names of the table and the cells...

    I'm waiting for your answer

    Have a nice day

    • Offizieller Beitrag

    Hi,

    I believe it has nothing to do with load or save.

    Problem is likely that after the LoadFromFile(..., true) the reference "table" does not point to the original table object anymore since LoadFromFile created a new one.

    Try this:

    wprichtext1.LoadFromFile( 'fic1.rtf' , true , '' ) ;
    WPRichText1.ReformatAll(false,false);
    table := wprichtext1.FirstPar;
    showmessage(table.name) ;
    showmessage(inttostr(table.RowCount)) ;

    Demoproject:
    https://www.wpcubed.com/ftp/ex/SaveTbl.zip

    Julian

  • Julian,

    your solution work for a simple table.

    The problem is in my program, cells have some images , I have rows with several cells (one cell per row, or 4 cells per row).

    When I save the table and I load it again, the table is "dispatched" in several "sections", and when I try to add a new row, it is inserted in the middle of my table (probably after the first "section").

    before saving, any row is inserted at the end, as I want it to be.

    I tried to do "table := lastPar" , but it doesn't work

    Could you give me a hint ?

    • Offizieller Beitrag

    Hi Petrut, oo wptools bug here - You have a

    WPRichText1.ProtectedProp := [ppParProtected]; //--- pour protéger les cellules qui ont le WPAT_ParProtected

    burried deep in the code. When you remove it, your code works again.

    To make it better servicable better change you code so You set protected and editoptions outside of the code which creates the text.

    The text creation You can wrap inside

    WPRichText1.Memo.DisableProtection;
    ...

    WPRichText1.Memo.EnableProtection;

    Some other notes:

    Code
    table.clear ;...wprichtext1.LoadFromFile( 'fic1.rtf' , true , '' ) ;

    table.Clear is not required.

    Later You use the Finder to locate cells:

    Code
    while WPRichText1.Finder.Next(#10) do    begin

    You should better do a loop like this:

  • Hi Julian,

    thank you very much for your help.

    I saw you also found the bug, that's a good thing.

    I will implement your sugestions, if I have any problem, I will contact you again.

    Have a nice day

    Petrut

  • Hi Julian,

    sorry for the long delay, but I was busy with another project.

    two days ago, I started to work on your suggestions, and, unfortunately, it doesn't work...

    I removed all the lines with WPAT_ParProtected, but this doesn't change absolutely nothing to the behaviour of the table : when I load a table from a file and I want to add a new row, it is not added AT THE END of the table.

    Is there a way to position programatically the new row at the end ?

    Thank you for your help

    Petrut

    • Offizieller Beitrag

    Hi,

    Zitat

    two days ago, I started to work on your suggestions, and, unfortunately, it doesn't work...

    If you need a new row at the end of a table you would use "low level" code. Basically you call "Duplicate" for the last row which is the last child of a table.

  • Julian,

    thank you for your quick answer, but this doesn't work.

    If you kept the source code I had sent you by email, you can test it :
    1 - you remove the WpAT_ParProtected everywhere in the code
    2 - you put a button "at the end" on the form with the code you posted here
    3 - you run the exe
    4 - you clik on "load" in order to load a file
    5 - you click on "at the end"

    and you can see the lines are not duplicated at the end of the table !

    if you didn't keep my project, I can send it to you again, with the new button, you will see this problem ; it's really a bug in the TABLE of wptools

    this is a blocking bug, how can I do to add a line AT THE END of the table AFTER having loaded a file ?

    thank you for your help

    • Offizieller Beitrag

    Hi,

    after you have loaded a file you need to move the cursor to the table where you want to add new rows. Or, better, you do not use the cursor and locate the TParagraph object which represents this table.

    I would expect you want to add to the last table in your text.

    So you can create some code to move there:

    This code first locates the last paragraph and then moves up until it finds a table:
    aTable := WPRichText1.LastPar;
    while (aTable<>nil) and (aTable.ParagraphType<>wpIsTable) do
    aTable := aTable.PrevPar;

    This is the complete code for "at the end":