TRichEdit finding protected text

464 Views Asked by At

I am working on a TRichEdit (Delphi XE2).

Is there any way i can check whether the richedit textbox contains protected text or not? Also the starting position of that protected text without iterating through the complete text.

Currently i am using the code below

source.SelStart := charNo; //source is richedit name and charno is the                     
                        //iterating loop 
source.SelLength := 1;
if (source.SelAttributes.Protected) then

The above code takes a lot of time for execution when the text is large.

This used to work fine in delphi 4

Can someone please tell why is the same code talking more time in delphi XE2 and less time in Delphi 4 also the proper way to do this in Delphi XE2?

1

There are 1 best solutions below

0
Remy Lebeau On

There is no way to search for text attributes. Iterating the individual characters and querying their attributes is the only option.

To speed up the code, you can:

  1. use the EM_SETSEL or EM_EXSETSEL window message instead of setting the SelStart and SelLength properties individually.

  2. Use the EM_SETEVENTMASK window message to turn off the RichEdit's internal notifications (such as EN_HSCROLL, EN_VSCROLL, and EN_SELCHANGE) while you are iterating.

  3. You might also consider using the WM_SETREDRAW window message to disable the RichEdit from repainting while you are iterating.