- Offizieller Beitrag
ZitatI'm not clear on which is the best way to determine the position, relative to the start of the paragraph, of the text cursor.
Pre-V5, I'd use <TWPRichText>.CPColNr, but that seems to be returning unexpected values (such as negative ones). So I tried <TWPRichText>.CPPosInPar. That seems to always be zero.
What's the best way to do this?
Please note that in WPTools 5 the cursor position is only determined by the paragraph and the position in the paragraph, no 'PTline' any more.
The paragraph is physcially stored in
WPRichgText.TextCursor.active_paragraph
the position
WPRichText.TextCursor.active_posinpar
This are indeed variables, no properties so you can be sure they refelct the current value.
CPColNr is a property which reflects the position in the current line (on screen!) - so this property should not be used if the text has not been formatted yet. In this case the result can be wrong!
CPPosInPar just reads out WPRichText.TextCursor.active_posinpar.
Please note that it usually not ideal to change the active_paragraph variable directly. Please use TextCursor.MoveTo and check the result for true. If the cursor was not moved that is FALSE.
ZitatIs <TWPRichText>.SetPosition and <TWPRichText>.GetPosition not as reliable in V5 as in earlier versions?
I've seen a number of instances in my application where they don't return the expect results or movement, and I'm starting to get the feeling that <TWPRichText>.CPPosition is the preferred approach, both for setting and retrieving the cursor position. Does this sound right to you?
CPPosition is the absolute text position relatively to the start of the text. Each paragraph end is counted as 1 character, too. So CPPosition is an exact value.
SetPosition / GetPosition has been mainly included to improve compatibility with 'old' WPTools. Please note that the 'line' part in fact is just a logical value, in WPZTools 4 it was based on the phsiacl pline pointer, and was exact. In WPTools it is based on the line array which stores nothing but offsets in the paragraph text. In general I would recommend to not use SetPosition / GetPosition.
Conclusion:
To read and write the position in the current paragraph use WPRichText.CPPosInPar.
For absolute position use WPRichText.CPPosition, this is the same as TextCursor.Position.
If you are use a paragraph is not deleted you can also store a par reference anbd then use TextCursorMoveTo to go to it agaian. This also works beteen text blocks, such as header and footer.
If questions are open please let me know.
Julian