简体   繁体   English

TRichEdit查找受保护的文本

[英]TRichEdit finding protected text

I am working on a TRichEdit (Delphi XE2). 我正在开发TRichEdit(Delphi XE2)。

Is there any way i can check whether the richedit textbox contains protected text or not? 有什么方法可以检查Richedit文本框是否包含受保护的文本? 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 这曾经在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? 有人可以告诉我为什么在Delphi XE2中使用相同的代码会花费更多的时间,而在Delphi 4中使用的时间却更少吗?

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. 使用EM_SETSELEM_EXSETSEL窗口消息,而不是分别设置SelStartSelLength属性。

  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. EN_HSCROLL EN_VSCROLL ,请使用EM_SETEVENTMASK窗口消息来关闭RichEdit的内部通知(例如EN_HSCROLLEN_VSCROLLEN_SELCHANGE )。

  3. You might also consider using the WM_SETREDRAW window message to disable the RichEdit from repainting while you are iterating. 您还可以考虑使用WM_SETREDRAW窗口消息在迭代时禁止RichEdit重新绘制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM