Page 1 of 1

How to get newly inserted item??

Posted: Fri Mar 29, 2019 2:38 pm
by kaka
Right after call AddNLTag() how can I get the correct ItemInfo? rve.GetCurrentItem? :?: :?: :?:

Thanks

Re: How to get newly inserted item??

Posted: Sun Mar 31, 2019 7:44 pm
by Sergey Tkachenko
Add*** methods append data to the end of the document.
If this method adds a single item (like rv.AddNLTag), you can access it using the index rv.ItemCount - 1.
For example:

Code: Select all

rv.AddNLTag('Hello', 0, 0, 'greetings');
Caption := rv.GetItemText(rv.ItemCount - 1) + rv.GetItemTag(rv.ItemCount - 1);
If you call Add*** method that can add multiple items (such as AddTextNL), you can compare the value of ItemCount before and after to calculate how many items are added to the end.

You cannot use GetCurrent*** methods to get information about items added by Add*** methods.
GetCurrent*** methods return information about the item at the caret position.
After calling Add*** methods the document is unformatted until you call Format, and the caret position is undefined.
GetCurrent*** methods can be used after editing methods for insertion (Insert***) - but only if this insertion was successful. Insertion may fail because of text protection, or if multiple table cells were selected.
Most insertion methods return True on success:

Code: Select all

if rve.InsertPicture(…) then
  rve.GetCurrentPictureInfo(…)