How to get ItemNo that after by use InsertStringWTag method
How to get ItemNo that after by use InsertStringWTag method
Now I have a question. When I use InsertStringWTag method, and I want to get this ItemNo. How can I do?
-
- Site Admin
- Posts: 17534
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
If the string is really inserted, this method returns True.
The method may fail (and return False) because the current text is protected, or because several cells are selected.
So you need to check a returned value.
The question you ask makes sense, because InsertStringTag always inserts one item (unlike InsertText that may insert several items, as well as it may modify text in existing text items).
InsertStringTag inserts text in RichViewEdit.TopLevelEditor, and moves the caret to the end of this item. So this item becomes current, and you can use TopLevelEditor.CurItemNo:
The method may fail (and return False) because the current text is protected, or because several cells are selected.
So you need to check a returned value.
The question you ask makes sense, because InsertStringTag always inserts one item (unlike InsertText that may insert several items, as well as it may modify text in existing text items).
InsertStringTag inserts text in RichViewEdit.TopLevelEditor, and moves the caret to the end of this item. So this item becomes current, and you can use TopLevelEditor.CurItemNo:
Code: Select all
if rve.InsertStringWTag('Hello world!', 0) then begin
Caption := 'We inserted '+rve.TopLevelEditor.GetItemText(rve.TopLevelEditor.CurItemNo);
// the same: Caption := 'We inserted '+rve.GetCurrentItemText;
end;