Page 1 of 1

Check if the line is empty

Posted: Mon Jan 11, 2021 3:42 pm
by tiagosis
how can I check if there are characters on a specific line? or check if a specific line is empty?

Re: Check if the line is empty

Posted: Tue Jan 12, 2021 11:02 am
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));