Deleting Blank Lines

General TRichView support forum. Please post your questions here
Post Reply
Richard King

Deleting Blank Lines

Post 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
Yernar Shambayev
Posts: 57
Joined: Wed Aug 31, 2005 6:46 pm

Post by Yernar Shambayev »

see InplaceEditor
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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;
Last edited by Sergey Tkachenko on Tue Sep 06, 2005 8:53 pm, edited 3 times in total.
Richard King

fix to code above

Post by Richard King »

Thanks Sergei - works great -- but note

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

rvData.DeleteItems(i,1)
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Thank you, I fixed the code
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Post Reply