How select text until the first End Of Line?

  • I want select text until the first End Of Line (until find #13).

    This is my bad code:

    procedure SelectUntilEOL;
    var
    start, endp : Integer;
    begin
    start := WPRichText1.CPPosition;
    repeat
    if Ord(WPRichText1.CPChar^)= 13 then
    begin
    endp := WPRichText1.CPPosition;
    WPRichText1.SetSelPosLen(start, endp-start);
    end;
    until not(WPRichText1.CPMoveNext);
    end;

  • This is my new code and very good with a new document but in the row of table don't found End Of Line.

    procedure SelectUntilEOL;
    var
    start, endp : Integer;
    findEOL: Boolean;
    begin
    findEOL := False;
    start := WPRichText1.CPPosition;
    repeat
    if WPRichText1.CPChar^= #13 then
    begin
    endp := WPRichText1.CPPosition;
    WPRichText1.SetSelPosLen(start, endp-start);
    findEOL := True;
    end;
    until not(WPRichText1.CPMoveNext) or findEOL;
    end;

  • Hello,

    I think, Your loop doesn't terminate when You found the first #13
    insert a break or exit command like the following:

    repeat
    if Ord(WPRichText1.CPChar^)= 13 then
    begin
    endp := WPRichText1.CPPosition;
    WPRichText1.SetSelPosLen(start, endp-start);

    break; // exits the repeat loop
    { OR }
    exit; // exits the procedure SelectUntilEOL

    end;
    until not(WPRichText1.CPMoveNext);

    This should work.
    Perhaps You have to adapt the 'endp' because at the moment it will include the #13 (I think)

  • Hello again,

    in WPTools 4 there is a function TWPCustomRichText.InTable
    You can check whether the cursor is in a table or not.
    And when I remember correctly there ist only 1 paragraph in each table cell.

    I hope this helps.

    • Offizieller Beitrag

    Hi,

    from the text I have the feeling you want to select to the end CR of a regular paragraph and to the end CR of the last table column if in a row.

    In WPTools 4 you can check if a table cell is the last in a row by checking for

    if paprIsLeftPar in ActiveParagraph^.prop

    You can use this as additional condition in your loop