Page 1 of 1

SetItemTag, AllTagsArePChars and integers

Posted: Wed Mar 08, 2006 1:31 pm
by martindholmes
Hi there,

For various reasons, I need to use rvoTagsArePChars to store strings in some item tags. However, in other tags, it would be easier to store integers. I'm looking at this code in the Help file:

var Tag: Integer;
S: String;
TagStr: PChar;
// Converting first text item and its tag string to upper case
MyRichView.GetTextInfo(0, S, Tag);
TagStr := StrNew(PChar(Tag));
TagStr := StrUpper(TagStr);
MyRichView.SetItemText(0, UpperCase(S));
MyRichView.SetItemTag(0, Integer(TagStr));

and noticing that the PChar is cast to an integer when storing it in the tag anyway. I also saw in another post that it is possible to "delete" a PChar tag by setting it to 0. If I store a regular integer in a tag with rvoTagsArePChars set, will this cause problems?

Cheers,
Martin

Posted: Thu Mar 09, 2006 7:43 am
by Sergey Tkachenko
You cannot use string and integer tags in the same document, because these tags are processed differently.
For example, when item in the tags-are-pchars mode is deleted, memory for its tag is freed. If its tag is a simple integer value, TRichView treats it as a pointer, and the component will attempt to free memory at incorrect address. It may lead to serious memory damages.

The only integer value that is allowed in the tags-are-pchars mode is 0 (treated as an empty string)

In any case, you can store integer value in text form, using IntToStr function to convert.

---

Update 2011-Oct-22: Starting from TRichView 13.3, all tags are strings. Initial values are empty strings (''). StrNew must not be used. rvoTagsArePChars is obsolete.

Posted: Thu Mar 09, 2006 12:57 pm
by martindholmes
Thanks Sergey.