how to remove Tag

General TRichView support forum. Please post your questions here
Post Reply
trojangirl

how to remove Tag

Post by trojangirl »

Trichview.addtag(str,i,i);

,
how to remove it when click?
Michel
Posts: 92
Joined: Fri Oct 14, 2005 2:56 pm
Contact:

Post by Michel »

I guess you'd use RichView.SetItemTag(ItemNumber, TagValue).
You must figure out what the Item number is (when it's clicked as you mentioned - or whenever).
As far as "removing" it, I don't think you can do that in the strict sense of the word. A RichView Tag is just an integer property of every Item, so you can just reset it to zero using the above function.
Note that when TagsArePChars, you can remove the pointed-to string (again, by passing zero), but your Tag doesn't look like a PChar kind, so this is not likely to be relevant.

Hope this helps,

Michel
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

In any cases (tags are PChars or not), "removing tag" can be done by assigning 0 to it.

Code for removing tag on clicking:

Code: Select all

// RichViewEdit1.OnRVMouseMove
procedure TForm3.RichViewEdit1RVMouseUp(Sender: TCustomRichView;
  Button: TMouseButton; Shift: TShiftState; ItemNo, X, Y: Integer);
var LRVData: TCustomRVFormattedData;
    LItemNo, LOffs: Integer;
    LPoint: TPoint;
begin
  if (Button<>mbLeft) or Sender.SelectionExists then
    exit;
  LPoint := Sender.ClientToDocument(Point(X, Y));
  if not Sender.GetItemAt(LPoint.X, LPoint.Y, LRVData, LItemNo, LOffs, True) then
    exit;
  LRVData.SetItemTag(LItemNo, 0);
end;
The code above can be used both for TRichView and TRichViewEdit. It cannot be undone/redone by user. If you need to make it undoable (only for TRichViewEdit):

Code: Select all

procedure TForm3.RichViewEdit1RVMouseUp(Sender: TCustomRichView;
  Button: TMouseButton; Shift: TShiftState; ItemNo, X, Y: Integer);
var LRVData: TCustomRVFormattedData;
    LItemNo, LOffs: Integer;
    LPoint: TPoint;
begin
  if (Button<>mbLeft) or Sender.SelectionExists then
    exit;
  LPoint := Sender.ClientToDocument(Point(X, Y));
  if not Sender.GetItemAt(LPoint.X, LPoint.Y, LRVData, LItemNo, LOffs, True) then
    exit;
  LRVData := TCustomRVFormattedData(LRVData.Edit);
  RichViewEdit1.SetItemTagEd(LItemNo, 0);
end;
Post Reply