Page 1 of 1
How to copy highlighted substrings to another RichEdit?
Posted: Wed Apr 08, 2009 3:45 pm
by ardani
I need to scan a first TRichEdit, read substrings background highlighted and copy them to another TRichEdit.
Thanks,
Armando Rodi
Posted: Wed Apr 08, 2009 6:44 pm
by Sergey Tkachenko
What do you mean by highlighting? Selection? Or some specific background color?
Posted: Thu Apr 09, 2009 9:38 am
by ardani
I mean colored background, for example, the following:
line1
line2 word1 word2 (line2, word2 background yellow)
line3
line4 word3 word4 (line4, word3 background green)
should become
line2 word1
line4 word4
Posted: Thu Apr 09, 2009 10:13 am
by ardani
I apologize for the mistake of writing.
I repeat the example.
I mean colored background, for example, the following:
line1
line2 word1 word2 (line2, word2 background yellow)
line3
line4 word3 word4 (line4, word4 background green)
should become
line2 word1
line4 word4
.
Posted: Thu Apr 09, 2009 12:47 pm
by Sergey Tkachenko
Do you mean:
line2 word2
line4 word4
Ok, a procedure for returning colored text is simple, but I do not understand about line breaks. The simple procedure returning colored text would return word2word4.
Posted: Thu Apr 09, 2009 2:42 pm
by Sergey Tkachenko
This procedure returns the highlighted text. Each text fragment is started from new line:
Code: Select all
procedure GetColoredText(rv: TCustomRichView; var Text: String);
var i: Integer;
begin
for i := 0 to rv.ItemCount-1 do
if (rv.GetItemStyle(i)>=0) and
(rv.Style.TextStyles[rv.GetItemStyle(i)].BackColor<>clNone) then begin
if Text<>'' then
Text := Text+#10#13+rv.GetItemText(i)
else
Text := rv.GetItemText(i);
end;
end;
This procedure ignores tables. If you need to process colored text in tables, let me know.
This procedure ignores tabs. If you need to process colored tabulators, let me know.
Posted: Fri Apr 10, 2009 2:55 pm
by ardani
Ok this was what I wanted.
Many thanks.