DelayedReformat - what is this ?

  • I have seen the DelayedReformat procedure mentioned as the solution to a number of different problems, including solving the problem where changes to the RTF component aren't visible until DelayedReformat is added to the code.

    Could you please expand a bit upon that procedure - when it's needed, why it's needed, and when it is not needed (so I don't superstitiously stick it in everywhere there's an available line for code!).

    Thanks....:)

    diamond

    • Offizieller Beitrag

    Thanks for the question,

    having this line in code almost comes without performance penalty since once call to 'DelayedReformat' will disable this procedure until the reformat has been processed.

    It will be processed when the application is idle (waiting on user input) the next time!

    This procedure does not work for window less memos (created by CreateDynamic) - here it will do nothing. The next will be not formatted until YOU say so.

    If you need the text to be formatted but you application cannot wait for the next time it is idle use the procedure ReformatAll to format the text at once. This procedure has also to be used for memos which do not have a parent window.

    For example if you are loading a text (LoadFromFile) any you need to print it right away you NEED ReformatAll - the same for the creation of a PDF file using wPDF.

    The LoadFromFile procedure internally calls 'DelayedReformat' so the text will be formatted before the user can edit it automatically. All the interfaces which manipulate the text, also InputText call DelayedReformat.

    But: The finder and replacements do NOT trigger DelayedReformat, Neither does the low level creation of Tables and paragraphs (TParagraph methods). SO here you need to add a DelayedReformat.

    As I said - the penalty is small. Even IF the text is formatted twice it does not take much time. The WPTools 5 format routine is able to paginate a 200 page text in about 300mms on my notebook.

    Ok, 300mms can be along time if it happens too often. Version 5.10 called Reformat too often when text in a table was edited. The upcoming 5.11 has a logic to only format the visible pages while the user is editing the text and applies a complete reformat only when the text is scrolled. So a quite long text can be edited quickly in 5.11.
    The preview control in 5.11 will also use a delayed time for the update of the display, this means it is only updated after the application was idle for about 800ms. You can see this in the the thumbnail preview in http://www.wpcubed.com/ftp/wp5demo.zip - this also makes editing a lot quicker.

    There is also the function ReformatAll( init, paint : Boolean );
    This function starts the format process at once. The boolean 'init' should be TRUE if a paragraph style was changed. It will cause the initialisation of the text, this means all character width will be recalculated. Usually 'init' should be false. When you work with a hidden editor control you need ReformatAll before you can print the file.