Check if the line is empty

General TRichView support forum. Please post your questions here
Post Reply
tiagosis
Posts: 41
Joined: Thu Apr 13, 2017 5:34 pm

Check if the line is empty

Post by tiagosis »

how can I check if there are characters on a specific line? or check if a specific line is empty?
Sergey Tkachenko
Site Admin
Posts: 17554
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Check if the line is empty

Post by Sergey Tkachenko »

What's an empty line? A paragraph that contains only a single empty text item.
I am not sure if the bulleted line may be considered as empty, let say that it is not.

What line do you need? If you need a line at the caret position in RichViewEdit1, the code is:

Code: Select all

var
  rve: TCustomRichViewEdit;
  ItemNo: Integer;

rve := RichViewEdit1.TopLevelEditor;
ItemNo := rve.CurItemNo;

IsCurrentLineEmpty := 
  // this is an empty text item
  (rve.GetItemStyle(ItemNo) >= 0) and (rve.GetItemText(ItemNo) = '') and 
  // and it starts a paragraph section
  rve.IsFromNewLine(ItemNo) and
  // and it is at the end of document, or the next item starts a new paragraph section
  ((ItemNo + 1 = rve.ItemCount) or (rve.IsFromNewLine(ItemNo + 1));
If bulleted empty lines are considered as empty, the code is:

Code: Select all

var
  rve: TCustomRichViewEdit;
  ItemNo: Integer;

rve := RichViewEdit1.TopLevelEditor;
ItemNo := rve.CurItemNo;

IsCurrentLineEmpty := 
  // this is an empty text item
  (rve.GetItemStyle(ItemNo) >= 0) and (rve.GetItemText(ItemNo) = '') and 
  // and it starts a paragraph section, or follows after a list marker  
  (rve.IsFromNewLine(ItemNo) or ((ItemNo - 1 >= 0) and (rve.GetItemStyle(ItemNo - 1) = rvsListMarker))) and
  // and it is at the end of document, or the next item starts a new paragraph section  
  ((ItemNo + 1 = rve.ItemCount) or (rve.IsFromNewLine(ItemNo + 1));
Post Reply