How to copy highlighted substrings to another RichEdit?

General TRichView support forum. Please post your questions here
Post Reply
ardani
Posts: 4
Joined: Fri Feb 01, 2008 7:41 pm

How to copy highlighted substrings to another RichEdit?

Post by ardani »

I need to scan a first TRichEdit, read substrings background highlighted and copy them to another TRichEdit.

Thanks,
Armando Rodi
Sergey Tkachenko
Site Admin
Posts: 17571
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

What do you mean by highlighting? Selection? Or some specific background color?
ardani
Posts: 4
Joined: Fri Feb 01, 2008 7:41 pm

Post 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
ardani
Posts: 4
Joined: Fri Feb 01, 2008 7:41 pm

Post 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

.
Sergey Tkachenko
Site Admin
Posts: 17571
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17571
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
ardani
Posts: 4
Joined: Fri Feb 01, 2008 7:41 pm

Post by ardani »

Ok this was what I wanted.

Many thanks. :D
Post Reply