Page 1 of 1

how to remove Tag

Posted: Fri Dec 02, 2005 4:00 am
by trojangirl
Trichview.addtag(str,i,i);

,
how to remove it when click?

Posted: Fri Dec 02, 2005 3:31 pm
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

Posted: Sat Dec 03, 2005 10:10 am
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;