Page 1 of 1

Remove line

Posted: Fri Nov 06, 2015 6:45 pm
by Ceprotec
I am using:

Code: Select all

while (SRichViewEdit1.RichViewEdit.SearchText('{******}', []) = True) and (PrimeiraFolha <> 'v') and (SRichViewEdit1.CurrentPage mod 2 = 0) do
begin
	SRichViewEdit1.RichViewEdit.SelectCurrentLine;
	SRichViewEdit1.RichViewEdit.DeleteSelection;
end;
But this text({******}) is inside a table, and I would like to remove the entire line, not just the cell contents.

Posted: Sat Nov 07, 2015 6:03 pm
by Sergey Tkachenko
"Lines" depend on document width. Do you mean paragraph?
Do you want to delete all paragraphs containing '{******}'?

Posted: Sun Nov 08, 2015 6:10 pm
by Ceprotec
Original document:
http://i.imgur.com/T7tDaad.jpg

Expectation:
http://i.imgur.com/uCWjuq3.jpg

Reality:
http://i.imgur.com/EvtayCU.jpg

I want to delete the entire line, not just the content of the cell.

Code "correct"

Code: Select all

SRichViewEdit1.SelectAll;

while (SRichViewEdit1.RichViewEdit.SearchText('{******}', []) = True) and (PrimeiraFolha <> 'v') and (SRichViewEdit1.CurrentPage mod 2 = 0) do
begin
   SRichViewEdit1.RichViewEdit.SelectCurrentLine;
   SRichViewEdit1.RichViewEdit.DeleteSelection;

   SRichViewEdit1.SelectAll;
end
[/url]

Posted: Mon Nov 09, 2015 10:51 am
by Sergey Tkachenko
Ok, I understand, you mean deleting the table row (or the table itself, if it has a single row).
It's more difficult, because if you select a table row and call DeleteSelection, selected cells are cleared, but the row is not deleted.
The code is below.

Code: Select all

procedure DeleteRowsWithText(rve: TCustomRichViewEdit; const Text: String);
var table: TRVTableItemInfo;
    ItemNo, ItemNo2, Data, Row, Col, RowCount, Offs, Offs2: Integer;
    rve2: TCustomRichViewEdit;
begin
  rve.SetSelectionBounds(0, rve.GetOffsBeforeItem(0), 0, rve.GetOffsBeforeItem(0));
  while rve.SearchText(Text, [rvseoDown]) do
    if rve.InplaceEditor<>nil then
    begin
      rve.GetCurrentItemEx(TRVTableItemInfo, rve2, TCustomRVItemInfo(table));
      ItemNo := table.GetMyItemNo;
      table.GetEditedCell(Row, Col);
      RowCount := table.RowCount;
      if RowCount = table.Cells[Row, Col].RowSpan then
      begin
        // deleting the whole table
        rve2.SetSelectionBounds(ItemNo, 0, ItemNo, 1);
        rve2.DeleteSelection;
        // deleting an empty line appeared after deleting the table
        SendMessage(rve2.Handle, WM_KEYDOWN, VK_DELETE, 0);
      end
      else
      begin
        // deleting rows
        rve2.BeginItemModify(ItemNo, Data);
        table.DeleteRows(Row, table.Cells[Row, Col].RowSpan, True);
        rve2.EndItemModify(ItemNo, Data);
        rve2.Change;
        // if the deletion was successfull...
        if table.RowCount < RowCount then
          // positioning the caret to continue the search
          if Row < table.RowCount then
          begin
            // in the next row after the deleted row(s)
            table.Rows.GetMainCell(Row, 0, Row, Col);
            table.EditCell(Row, Col);
          end
          else
          begin
            // or after the table
            rve2.SetSelectionBounds(ItemNo, 1, ItemNo, 1);
          end;
      end;
    end;
end;

Posted: Mon Nov 09, 2015 11:10 am
by Ceprotec
It worked.

Thank you!