How to read the text in a line

  • I use the following code to read three lines of text:

    What is the equivalent code using WPTools6?

    Thank you in advance for your help.

    Kind regards,

    Carlos Borrero

    • Offizieller Beitrag

    Hi,

    WPTools 4 does not use line records like WPTools 4 did. The paragraphs are kept intact, which usually make things a lot easier when accessing the text.

    The TParagraph object has some line methods, they report the start and the length of the characters in one text line. Useing this values You can use GetSubText to extract the relevant characters.

    Do not use CPMoveDown - they are for user interaction and use some extra code to solve the undefined state, when the cursor is at the end of one line - since this can be also the start of the next line.

    Julian

  • The following code doesn't work either:


    The problems seems to be on the following line:
    LocalLinea := WPRichText_Work.TextCursor.active_line;

    I suppose WPRichText_Work.TextCursor.active_line reads the line number, within a paragraph.

    But seems it doesn't.

    Any ideas on how to know the line number within a paragraph that corresponds to CPPosition?

    LineOffset and LineLength need to have this parameter.

    Kind regards,

    Carlos Borrero

    • Offizieller Beitrag

    When You start Your code, is the text already reformatted? If not, no lines are
    available.

    The example I wrote can also be coded in such a sub procedure

    Code
    function GetThreeLines(par : TParagraph; pos_in_par : Integer) : string;   var s, e : Integer;   begin       s := par.LineOfPos(pos_in_par);       if s<par.LineCount-1 then e := s+1 else e := s;       if s>0 then dec(s);        s := par.LineOffset(s);       e := par.LineOffset(e)+par.LineLength(e);       Result := par.GetSubText( s, e-s );   end;

    which is used like this:

    GetThreeLines( WPRichText1.ActiveParagraph, WPRichText1.ActivePosInPar )

    Please use pos_in_par wherever You can and not line indexes (used to ber
    pointers)

    But is it possible that You do not need to read the lines of the paragraph but
    the lines of a page? I mean, that you need the last line of the previous
    paragraph in case your refence is on the first line of a paragraph. In this case
    the sub procedure will NOT work. But you entry post did not suggest this.

    I You need that:

    Code
    s := WPRichText1.CPLine;   if WPRichText1.CPMoveUpLine then   begin     s := WPRichText1.CPLine + s;     WPRichText1.CPMoveDownLine;   end;   if WPRichText1.CPMoveDownLine then   begin     s := s + WPRichText1.CPLine;     WPRichText1.CPMoveUpLine;   end;

    BTW:

    CPMoveNext would not change anything, but the text must be formatted.

    Julian