Page 1 of 1

Delete items cascade

Posted: Tue Sep 21, 2010 11:54 am
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?

Posted: Tue Sep 21, 2010 12:58 pm
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;

Posted: Tue Sep 21, 2010 2:09 pm
by vit
Thank you! It's works fine!