Remove line

General TRichView support forum. Please post your questions here
Post Reply
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Remove line

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

"Lines" depend on document width. Do you mean paragraph?
Do you want to delete all paragraphs containing '{******}'?
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Post 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]
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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;
Last edited by Sergey Tkachenko on Mon Nov 09, 2015 11:24 am, edited 1 time in total.
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Post by Ceprotec »

It worked.

Thank you!
Post Reply