rvico TRichView Reference | TRichView

TCustomRichView.DeleteItems

Top  Previous  Next

Removes the specified number of items (Count) from the document, starting from the FirstItemNo-th item.

procedure DeleteItems(FirstItemNo, Count: Integer);

Items are indexed from 0 to ItemCount-1. Items of subdocuments (table cells) are not included in the items range of the main document; for items in cells, use Cell.GetRVData.DeleteItems.

Method type: viewerstyle viewer-style.

Be careful: this method can produce invalid document.

Example 1: deleting all empty lines

procedure DeleteBlankLines(RVData: TCustomRVData);

var i,r,c: Integer;

    table: TRVTableItemInfo;

begin

  for i := RVData.ItemCount-1 downto 0 do

    if RVData.IsParaStart(i) and (RVData.GetItemStyle(i)>=0and 

      (RVData.GetItemTextR(i)=''and (RVData.ItemCount>1then 

      RVData.DeleteItems(i,1)  

    else if RVData.GetItemStyle(i)=rvsTable then begin 

      table := TRVTableItemInfo(RVData.GetItem(i)); 

      for r := 0 to table.RowCount-1 do 

        for c := 0 to table.ColCount-1 do 

          if table.Cells[r,c]<>nil then 

            DeleteBlankLines(table.Cells[r,c].GetRVData); 

    end

end

DeleteBlankLines cannot be undone/redone. If called for editor, the editor's undo buffer becomes incorrect, so call ClearUndo.

Call:

DeleteBlankLines(RichViewEdit1.RVData); 

RichViewEdit1.ClearUndo

RichViewEdit1.Format

Example 2: deleting empty lines at the end of document

procedure DeleteTrailingBlankLines(RVData: TCustomRVData); 

var i: Integer; 

begin 

  for i := RVData.ItemCount-1 downto 1 do 

    if RVData.IsParaStart(i) and (RVData.GetItemStyle(i)>=0and 

     (RVData.GetItemTextR(i)=''then 

      RVData.DeleteItems(i,1

    else 

      break; 

end;

 

See also:

DeleteSection;

DeleteParas.


TRichView © trichview.com