delphitrichedit

How to select certain table rows in TRichedit with Delphi (Xe10)


i have a TjvRichedit control containing a table with some rows/cells filled with text. I want to select some entire rows (eg. rows firstLine and firstLine+1) and copy them to clipboard (or to a stream). I use the code bellow :

SelStart := Perform(EM_LINEINDEX, firstLine, 0);
SelLength:= length(lines[firstLine]) + length(lines[firstLine+1]);
CopyToClipboard;

but it selects from firstLine to firstLine+3 (even selects rows from the next table !). If i reduce the length (eg. SelLength:= 2) it selects two lines! How can i do exactly what i want, please ?


Solution

  • If the selection is at the beginning of a tablerow, you have to exclude the first two characters

    RichEdit1.SelStart := Perform(EM_LINEINDEX, LineNo, 0) + 2; // start two chars beyond the linestart
    RichEdit1.SelLength:= Perform(EM_LINELENGTH, RichEdit1.SelStart,0) - 2; // decrease the whole length by these two chars
    

    The same in case of more than one lines (decrease the whole length only once by two)