trichview.com

trichview.support




Re: When to call Format?


Return to index


Author

Message

Sergey Tkachenko

Posted: 05/05/2005 19:27:41


"Editor-style methods" (such as InsertText, ApplyTextStyle, DeleteSelection)

reformat the document themselves, it's not necessary to call Format after

them. The only effect of calling Format after them is slowing down and

resetting the caret to the beginning of the document.

For example, if you need to delete some text in editor, you can make it as

an undoable editing operation - select this text fragment and then call

DeleteSelection. No call of Format is requred.

Actually, many TRichView users overuse Format (according to code samples

that they sent to me).


When Format is required?

First, after you generated or loaded document. The sequence is:

rve.Clear;

<create doc here, for example rve.LoadRVF or rve.AddNL)

rve.Format;

In this case, the caret cannot be in table cell.


Any modification in TRichView (not editor) requires call of Format before

displaying (the only exception is DeleteParas method).In this case, the

caret cannot be in table cell (because there is no caret in TRichView)


As it was said, it's highly recommended to modify document in TRichViewEdit

using editing methods.

Calling non-editor method (such as DeleteItems or AddNL) after editing

methods or operations can make data in undo buffer incorrect, and next

undo/redo operation will fail. This problem can be solved by calling

ClearUndo, though.

In any case, if you still want to apply non-editor methods to the existing

document in TRichViewEdit, I do not recommend to to it when the cell inplace

editor is active.

You can reset the caret postion to the beginning:

rve.SetSelectionBounds(0, rve.GetOffsBeforeItem(0), 0,

rve.GetOffsBeforeItem(0))


Addition information: the help file, "Viewer vs Editor" topic.



> Hi there,

>

> I've just learned from your earlier post that calling Format can now be

> dangerous in v 1.9. I'm calling that in all sorts of places in my code,

> based on instructions still in the Help file which warn that the

> document must be formatted before you can call various functions. The

> document becomes unformatted, according to the Help, after calling

> functions such as DeleteItems, and we must call Format before we can

> call "any editor-style method". However, according to your recent post,

> "calling Format is dangerous when the caret is in table cell."

>

> So I'm not sure what to do when, for example, the caret is in a table

> cell, I've deleted some items, and I need to format the document before

> calling another editor-style method. Is there a safe way to format the

> document?

>

> All help appreciated,

> Martin





Powered by ABC Amber Outlook Express Converter