tags:

views:

589

answers:

4

Hi All

I would greatly appreciate some help on anyone that has experience in working with Rich Edit controls in Delphi that support Regular Expression searches.

I've toyed around with RichEdit.dll V3 based controls only to find that MS's ITextSelection.FindText implementation uses some MS Mickey Mouse variant of regular expressions (i.e. ^p for paragraph) and so on.

Regular expression searches against TRichEdit1.text return mismatched SelStart locations due to hidden RTF formatting.

I guess this rules out any RichEdit.dll based controls/components unless someone could suggest a workaround?

I've also had a look at Dream Rich Editor but am worried that this is longer maintained (as of 2005). Otherwise, this looks ideal but cannot find any contact information to ask what ReGex syntax is supported (i.e. PCRE?)

Another option was ProfHTMLEdit but that chocked on the 2MB HTML file I tested it against. Editing was also non responsive on large files. Shame, as the control looked promising.

Yet another component was TRichView but sadly that does not appear to support searching using Regular Expressions.

Simply put, my requirement is a Delphi 7 control that allow simple editing (i.e. bold, italic, selection alignments) and most importantly, the ability the search using Regular Expressions (preferably PCRE.. but not necessarily). Not too fussed what the underlying storage mechanism (rtf, html, xyz) is.

Any help or pointers/hints/tips greatly appreciated.

+2  A: 

This link may help. I can't speak from experience with the components mentioned there, but as a HelpScribble user of many years I can say that Jan Goyvaert's support for his products is consistently outstanding. You might try contacting him - he may know of a useful component. It does occur to me that if you copied the text from a RichEdit control to a string variable (without formatting), you may be able to search that then map that position back to the text in your control. Just a thought.

Argalatyr
Many thanks for the answer."you may be able to search that then map that position back to the text in your control. Just a thought."I did indeed try doing a regex search on the plain text but match positions on the plain text token matches don't map back when using RichEdit.SelStart ... sadly as life would have been much much simpler :)
Nazar
Unfortunately, Jan Goyvaerts does not know of any rich edit Delphi components with built-in regex features. Copying the plain text into TPerlRegEx and using the returned offsets and lengths to tell the rich edit control to make the selection and/or replacement should work.
Jan Goyvaerts
+1  A: 
lkessler
Thanks for the comments lkessler. I'll drop the TRichView developers an email along these lines. I did a search on their support forums, but did not see much traffic regarding regex support.Cheers.
Nazar
Awsome! I have used TRegExpr before but its not as good as TPerlRegEx. Thanks for the forum link! I've dropped the developers and email and will checkout the forum link you sent. Awsome * 2!
Nazar
I have used TRegExpr before but its not as good as TPerlRegEx but should be able to use the same logic and easily replace one component for another.
Nazar
+2  A: 

It's strange, but most lists of regexp components for Delphi don't mention the one I use almost all of the time:

VBScript_RegExp_55_TLB.pas

gotten by importing the "Microsoft VBScript Regular Expressions 5.5" type library. It's gotten the VBScript label because it was introduced with VBScript/Javascript 5.5 together with Internet Explorer 5.5, which means you're sure end-user client have the library if you require users to have IE5.5 or above. I haven't combined it with a rich-edit control though.

Stijn Sanders
+1  A: 

I've done some more research on TRichEdit and RichEd20.dll based on the excellent feedback to this question.

Some background. I want to use TPerlRegEx to search a TRichEdit control contents and highlight matched results. Previous attempts using RichEdit1.Lines.Text as the search subject resulted in a mismatched RegEx MatchedExpressionOffset and RichEdit1.SelStart.

I had thought that this was due to RTF formatting.. but that was just me having a brain fart!

On closer examination, there are two issue that need to be taken into consideration when not using RichEdit.FindText:

  1. If using RichEdit.Text or RichEdit.Lines.Text then be aware that these contain extra #$D and #$A carriage return and line feed characters.
  2. If using TPerlRegex.MatchedExpressionOffset then this is one based whilst TRichEdit.SelStart is zero based.

To correctly find the SelStart using TPerlRegex carriage returns and line feeds need to be taken into consideration when determining the SelStart.

Nazar
When using Delphi 2009 and later, you also need to take into account that TPerlRegEx works with UTF8String, and the offsets are UTF-8 byte lengths. The reason for that is that the underlying PCRE library uses UTF-8.
Jan Goyvaerts