Page 1 of 1

Deleting Blank Lines

Posted: Wed Aug 31, 2005 6:06 am
by Richard King
How to delete blank lines?

The following code works:

rvP1.DeleteSelection;
if rvP1.GetCurrentItemText = '' then
rvP1.DeleteParas(rvP1.CurItemNo, rvP1.CurItemNo);

BUT not when selection is in a table cell (previously the code has done a rvP1.SearchText( 'some text', [rvseoDown] ).

How to write something which will work inside and outside a table ??

Thanks

Posted: Wed Aug 31, 2005 7:13 pm
by Yernar Shambayev
see InplaceEditor

Posted: Thu Sep 01, 2005 12:54 pm
by Sergey Tkachenko
Should it be an editing operation (that can be undone/redone by user)?

If not, the code is below:

Code: Select all

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)>=0) and
      (RVData.GetItemText(i)='') and (RVData.ItemCount>1) then
      RVData.DeleteItems(i,1)  
    else if RVData.GetItemStyle(i)=rvsTable then begin
      table := TRVTableItemInfo(RVData.GetItem(i));
      for r := 0 to table.Rows.Count-1 do
        for c := 0 to table.Rows[r].Count-1 do
          if table.Cells[r,c]<>nil then
            DeleteBlankLines(table.Cells[r,c].GetRVData);
    end;
end;
Call:

Code: Select all

DeleteBlankLines(RichView1.RVData);
RichView1.Format;

fix to code above

Posted: Fri Sep 02, 2005 1:01 am
by Richard King
Thanks Sergei - works great -- but note

the line rv.DeleteItems(i,1) needs to be

rvData.DeleteItems(i,1)

Posted: Fri Sep 02, 2005 3:08 pm
by Sergey Tkachenko
Thank you, I fixed the code

Posted: Tue Sep 06, 2005 8:55 pm
by Sergey Tkachenko
I modified the code: added the condition (RVData.ItemCount>1), to prevent deleting the last RVData item.
It's ok to delete all items from TRichView.
It's ok to delete all items from TRichViewEdit (one empty line will be readded by Format).
But it's not ok to delete all items from table cells.