Deleting Blank Lines

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

Deleting Blank Lines

Post by Richard King » Wed Aug 31, 2005 6:06 am

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 » Wed Aug 31, 2005 7:13 pm

see InplaceEditor

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

Post by Sergey Tkachenko » Thu Sep 01, 2005 12:54 pm

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 » Fri Sep 02, 2005 1:01 am

Thanks Sergei - works great -- but note

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

rvData.DeleteItems(i,1)

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

Post by Sergey Tkachenko » Fri Sep 02, 2005 3:08 pm

Thank you, I fixed the code

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

Post by Sergey Tkachenko » Tue Sep 06, 2005 8:55 pm

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