SetItemTag, AllTagsArePChars and integers

General TRichView support forum. Please post your questions here
Post Reply
martindholmes
Posts: 131
Joined: Mon Aug 29, 2005 12:03 pm

SetItemTag, AllTagsArePChars and integers

Post 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
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Last edited by Sergey Tkachenko on Sat Oct 22, 2011 7:14 pm, edited 1 time in total.
martindholmes
Posts: 131
Joined: Mon Aug 29, 2005 12:03 pm

Post by martindholmes »

Thanks Sergey.
Post Reply