Delete items cascade

General TRichView support forum. Please post your questions here
Post Reply
vit
Posts: 115
Joined: Tue Feb 03, 2009 3:11 pm

Delete items cascade

Post by vit »

Is need to delete several items (defined by tags) when user deletes some item with specified tag.

Seems like I can't use OnItemAction event:

Code: Select all

procedure TForm1.OnItemAction(Sender: TCustomRichView;
  ItemAction: TRVItemAction; Item: TCustomRVItemInfo;
  var Text: TRVRawByteString; RVData: TCustomRVData);
begin
  if (ItemAction = rviaMovingToUndoList) and (Item.Tag > 0) then
  begin
    DeleteItems(-Item.Tag);
    srveContent.RichViewEdit.ClearUndo;
    srveContent.RichViewEdit.Format;
  end;
end;

procedure TForm1.DeleteItems(const ATag: Integer);
var
  Finder: TItemFinder; {Performs searching sequence of items with specified tag and return RVData in which sequence is founded, start item no and items count.}
begin
  Finder := TItemFinder.Create(ATag, srveContent.RichViewEdit.RVData);
  try
    if Finder.Search then
    begin
      Finder.RVData.SetSelectionBounds(Finder.Start, 0, Finder.Start, 0);
      Finder.RVData.DeleteItems(Finder.Start, Finder.Count);
    end;
  finally
    Finder.Free;
  end;
end;
And execution is fails on srveContent.RichViewEdit.Format;

Any suggestions?
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

1) You cannot modify document in OnItemAction. Use PostMessage to delete after (if you need an example, let me know)
2) Use editing operations: DeleteSelection instead of DeleteItems:

Code: Select all

      Finder.RVData.Edit;
      with Finder.RVData.GetRVData as TCustomRVFormattedData do
        SetSelectionBounds(Finder.Start, GetOffsBeforeItem(Finder.Start), Finder.Start+Finder.Count-1, GetOffsAfterItem(Finder.Start+Finder.Count-1); 
      RichViewEdit1.DeleteSelection;
vit
Posts: 115
Joined: Tue Feb 03, 2009 3:11 pm

Post by vit »

Thank you! It's works fine!
Post Reply