Page 1 of 1

How to get ItemNo that after by use InsertStringWTag method

Posted: Mon Nov 15, 2010 8:06 am
by sky_234
Now I have a question. When I use InsertStringWTag method, and I want to get this ItemNo. How can I do?

Posted: Tue Nov 16, 2010 8:52 am
by Sergey Tkachenko
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:

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;

Posted: Tue Nov 16, 2010 8:57 am
by sky_234
thanks you help