0

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 ?

JimPapas
  • 715
  • 2
  • 12
  • 27
  • What do you mean by **firstLine and firstLine+1)**? you mean the first line + first char from the second line? – Ilyes Nov 27 '16 at 20:41
  • I try it on Delphi 7 & Delphi 10 seattle & work fine. – Ilyes Nov 27 '16 at 21:29
  • You can see my updates & try it. – Ilyes Nov 27 '16 at 21:40
  • I tried your code but it has the same problem i faced with mine. It happens when the document has **tables** It seems that counts some invisible characters (beyond the CR+LF of each line). So this is my problem. Witch and how many are they ? – JimPapas Nov 28 '16 at 00:40
  • I saw that the text of every table row with some cells is represented by a richEdit line. The text of such a line begins with characters #$FFF9#$D and ends with #$FFF9#$D. The text between cells is divided by #7 The length(richedit.lines[i]) counts all those characters but the selstart and sellength doesn't (?). In this case how can i solve this ? – JimPapas Nov 28 '16 at 01:22

2 Answers2

1

To select the first Line and copy the selected text to Clipboard:

RichEdit1.SelStart:=0;
RichEdit1.SelLength:=length(RichEdit1.Lines.[0]);
RichEdit1.CopyToClipboard;

To select the first Line + the first char from the second Line and copy the selected text to Clipboard :

RichEdit1.SelStart:=0;
RichEdit1.SelLength:=length(RichEdit1.Lines[0])+2;
RichEdit1.CopyToClipboard;

To select the second Line :

RichEdit1.SelStart:=length(RichEdit1.Lines[0])+1;
RichEdit1.SelLength:=length(RichEdit1.Lines[1]);
Ilyes
  • 14,640
  • 4
  • 29
  • 55
0

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)

JimPapas
  • 715
  • 2
  • 12
  • 27