How to get ItemNo that after by use InsertStringWTag method

General TRichView support forum. Please post your questions here
Post Reply
sky_234
Posts: 24
Joined: Sat Feb 18, 2006 1:27 pm

How to get ItemNo that after by use InsertStringWTag method

Post by sky_234 »

Now I have a question. When I use InsertStringWTag method, and I want to get this ItemNo. How can I do?
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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;
sky_234
Posts: 24
Joined: Sat Feb 18, 2006 1:27 pm

Post by sky_234 »

thanks you help
Post Reply