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?
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:
use the
EM_SETSEL
orEM_EXSETSEL
window message instead of setting theSelStart
andSelLength
properties individually.Use the
EM_SETEVENTMASK
window message to turn off the RichEdit's internal notifications (such asEN_HSCROLL
,EN_VSCROLL
, andEN_SELCHANGE
) while you are iterating.You might also consider using the
WM_SETREDRAW
window message to disable the RichEdit from repainting while you are iterating.